ã¯ããã«
Google ãããé常ã«é¢ç½ãããªã½ããã¦ã§ã¢ããªãªã¼ã¹ããã¾ããï¼
ãã®åã Native Client ãªãã¨ãã©ã¦ã¶ä¸ã§ X86 ã®ãã¤ããªãåããã¦ãã¾ãããã§ãã
ããã¯ãããï¼
ãã£ãã試ãã¦ã¿ããã¨æãã¾ãããã®éç¨ãé次æ´æ°ãã¦ããã¾ãã
èªåã試ããã¨ãã®ç°å¢
èªåã試ãç°å¢ã¯ã以ä¸ã®éãã§ãã
æºå
ã§ã¯ããã£ããæºåããã¾ãããã
http://nativeclient.googlecode.com/svn/trunk/nacl/googleclient/native_client/documentation/getting_started.html ãåèã«ãã£ã¦ã¿ã¾ãã
ç°å¢ä¸å¼ããã¦ã³ãã¼ã
ã¾ãã¯ã以ä¸ãã nacl_mac_0.1_9308700.tgz ããã¦ã³ãã¼ããã¦ããã¾ãã
http://code.google.com/p/nativeclient/downloads/list
$ wget http://nativeclient.googlecode.com/files/nacl_mac_0.1_9308700.tgz --2008-12-09 15:10:07-- http://nativeclient.googlecode.com/files/nacl_mac_0.1_9308700.tgz nativeclient.googlecode.com ãDNSã«åããããã¦ãã¾ã... 74.125.47.82 nativeclient.googlecode.com|74.125.47.82|:80 ã«æ¥ç¶ãã¦ãã¾ã... æ¥ç¶ãã¾ããã HTTP ã«ããæ¥ç¶è¦æ±ãéä¿¡ãã¾ãããå¿çãå¾ ã£ã¦ãã¾ã... 200 OK é·ã: 83237741 (79M) [application/x-gzip] `nacl_mac_0.1_9308700.tgz' ã«ä¿åä¸ 100%[==================================================================================================================>] 83,237,741 2.61M/s æé 36s 2008-12-09 15:10:44 (2.21 MB/s) - `nacl_mac_0.1_9308700.tgz' ã¸ä¿åå®äº [83237741/83237741]
解å
tgz ã ã£ãã®ã§ã tar ã§è§£åãã¾ãã
$ tar xvfz nacl_mac_0.1_9308700.tgz
ä¸ãè¦ã¦ã¿ã
tar ãã㨠nacl ã¨ãããã£ã¬ã¯ããªã«ããããã¨è§£åããã¾ããã
解åããããã£ã¬ã¯ããªã tree ãã¦ã¿ã¾ããã
ng$ cd .. $ tree -dL 3 nacl nacl `-- googleclient |-- native_client | |-- common | |-- documentation | |-- gtest | |-- include | |-- intermodule_comm | |-- ncv | |-- nonnacl_util | |-- npapi_plugin | |-- scons-out | |-- service_runtime | |-- site_scons | |-- site_scons_general | |-- tests | |-- third_party | |-- tools | `-- tools_bin `-- third_party |-- binutils |-- gcc |-- gnu_binutils |-- gtest |-- libxt |-- newlib |-- npapi |-- scons `-- sdl 28 directories
third_party/sdl ã¨ãããã£ã¬ã¯ããªãããã¾ããï¼ã¯ã¯ã¯ã¯ãã¾ãã
ãµã³ãã«ãå®è¡ãã¦ã¿ã
ãµã³ãã«ã¯ã nacl/googleclient/native_client/tests/ ã®ä¸ã«å ¥ã£ã¦ããã¿ããã§ãã
tree -dL 1 nacl/googleclient/native_client/tests/ nacl/googleclient/native_client/tests/ |-- Frameworks |-- app_lib |-- cloudfs |-- createthreads |-- earth |-- eviltests |-- fib |-- file |-- hello_world |-- imc_shm_mmap |-- life |-- mandel |-- mandel_nav |-- mm_init |-- mmap |-- noop |-- npapi_bridge |-- npapi_hw |-- npapi_pi |-- nrd_xfer |-- null |-- plug_univ |-- quake |-- srpc |-- srpc_hw |-- syscalls |-- tone |-- voronoi `-- xaos 29 directories
ãªãããããããããã¾ãã
ã§ã¯ã life ã¨ãããµã³ãã«ãå®è¡ãã¦ã¿ã¾ãããï¼
$ cd nacl/googleclient/native_client/tests/ $ python run.py
ãããããªãããã©ã¤ãã²ã¼ã ãç«ã¡ä¸ããã¾ããï¼
ãã£ã¬ã¯ããªã®ä¸èº«ãè¦ã¦ã¿ã¾ãããã
$ ls -la total 64 drwxr-xr-x 2 amachang staff 272 12 8 12:45 . drwxr-xr-x 31 amachang staff 1054 12 8 12:45 .. -r--r--r-- 1 amachang staff 1882 12 8 12:45 Makefile -r--r--r-- 1 amachang staff 166 12 8 12:45 README.txt -r--r--r-- 1 amachang staff 1874 12 8 12:45 SConscript.nacl -r-xr-xr-x 1 amachang staff 9795 12 8 12:45 life.cc -r--r--r-- 2 amachang staff 1134 12 8 12:45 life.html -r-xr-xr-x 1 amachang staff 1786 12 8 12:45 run.py
ãã«ãç¨ã® Makefile 㨠SConscript ã¨ãã½ã¼ã¹ã³ã¼ã life.cc ã¨ã html ã«è²¼ä»ããããã® life.htmlãååå®è¡ç¨ã® run.py ã£ã¦æãã§ããã
ã¡ãã£ã¨è±ç·ï¼ã½ã¼ã¹ã³ã¼ããè¦ãè¦ãã¦ã¿ã
ã½ã¼ã¹ã³ã¼ããã¡ãã£ã¨è¦ã¦ã¿ã¾ãããã
include ãè¦ãã¨ã以ä¸ã®ããã« nacl/nacl_* ã¨ãããã¡ã¤ã«ã include ãã¦ãã¾ãã
standalone ã§å®è¡ããæã¯ãéãããããèªã¿è¾¼ãããã§ããã#if !defined(STANDALONE) #include <nacl/nacl_av.h> #include <nacl/nacl_srpc.h> #else #include "native_client/common/standalone.h" #endifæç»ã¯ã以ä¸ã®ããã« nacl_video_update ã« uint32_t ã®ãããã¡ã渡ãã¦ããããã§ãã
struct Surface { int width, height, pitch; uint32_t *pixels; Surface(int w, int h) { width = w; height = h; pitch = w; pixels = new uint32_t[width * height]; } ~Surface() { delete[] pixels; } }; ï¼ ï¼ // Copies sw rendered life image to screen void Life::Draw() { int r; r = nacl_video_update(surf_->pixels); if (-1 == r) { printf("nacl_video_update() returned %d\n", errno); } }詳ãããã¨ã¯ãã®æç¹ã§ã¯ããåããã¾ããã
ã§ãããã®ã¢ããªã±ã¼ã·ã§ã³ã¯ 341 è¡ã¨ããçãã³ã¼ãã§åãã¦ããããã§ãã
ã¡ãã£ã¨è±ç·ï¼ run.py ã¯ä½ããã£ã¦ããã®ï¼
追ãããã¦ã¿ããã run.py ã¯ä»¥ä¸ã®ã³ãã³ããå®è¡ãã¦ããã¿ããã§ãã
$ nacl/googleclient/native_client/scons-out/dbg-mac/staging/sel_ldr -d -f nacl/googleclient/native_client/scons-out/nacl/staging/life.nexesel_ldr ã¨ããããã°ã©ã ã¯ãã¹ã¿ã³ãã¢ãã¼ã³çã® flash player ã®ãããªãã®ã§ nexe ã¨ããã swf ã®ãããªãã®ãªã®ã§ãããã
- -f ãªãã·ã§ã³ã¯ãã¡ã¤ã«æå®
- -d ãªãã·ã§ã³ã¯ãããã°
ã¨ããæå³ã ããã§ãã
life.nexe ã¨ããã®ã¯ã©ããããã¡ã¤ã«ãªã®ãï¼
ã¡ãã£ã¨æ°ã«ãªãã®ã§ã file ãã¦ã¿ã¾ãã
$ file scons-out/nacl/staging/life.nexe scons-out/nacl/staging/life.nexe: ELF 32-bit LSB executable, Intel 80386, version 1, statically linked, not strippedã©ãããã *.nexe 㯠ELF 32-bit LSB ãã¤ããªï¼ãªããã¯ã¹ã®å®è¡ãã¡ã¤ã«ã®å½¢å¼ï¼ã ã¨ãããã¨ãåããã¾ããã
ãã©ã°ã¤ã³ããã«ããã
SCons ã§ãã«ãåºæ¥ãããã§ãã
$ cd googleclient/native_client $ scons --help scons: Reading SConscript files ... EnvironmentError: No module named component_setup: File "/Users/amachang/nc/nacl/googleclient/native_client/SConstruct", line 52: COMPONENT_LIBRARY_PUBLISH = True, File "/opt/local/lib/scons-0.98.4/SCons/Environment.py", line 933: apply_tools(self, tools, toolpath) File "/opt/local/lib/scons-0.98.4/SCons/Environment.py", line 106: env.Tool(tool) File "/opt/local/lib/scons-0.98.4/SCons/Environment.py", line 1582: tool = apply(SCons.Tool.Tool, (tool, toolpath), kw) File "/opt/local/lib/scons-0.98.4/SCons/Tool/__init__.py", line 89: module = self._tool_module() File "/opt/local/lib/scons-0.98.4/SCons/Tool/__init__.py", line 140: raise SCons.Errors.EnvironmentError, e
æããã¦ãã¾ãã¾ããï¼ï¼
ã©ãããã Native Client ãç¨æãã scons ã使ãã¨ãããã¨ãããã§ããã
$ ./scons --help scons: Reading SConscript files ... ====================================================================== Building nexe binaries using sdk at [/Users/amachang/nc/nacl/googleclient/native_client/tools_bin/mac/sdk/nacl-sdk] ====================================================================== ====================================================================== SDL build enabled, this is somewhat experimental Using version in /Users/amachang/nc/nacl/googleclient/native_client/../third_party/sdl/osx/v1_2_13 ====================================================================== *** Solution file generation skipped (not supported on this platform). scons: done reading SConscript files. Additional options for SCons: --mode=MODE Specify build mode (see below). --host-platform=PLATFORM Force SCons to use PLATFORM as the host platform, instead of the actual platform on which SCons is run. Useful for examining the dependency tree which would be created, but not useful for actually running the build because it'll attempt to use the wrong tools for your actual platform. --site-path=DIRLIST Comma-separated list of additional site directory paths; each is processed as if passed to --site-dir. --verbose Print verbose output while building, including the full command lines for all commands. --brief Print brief output while building (the default). This and --verbose are opposites. Use --silent to turn off all output. --retest Rerun specified tests, ignoring cached results. ====================================================================== Help for NaCl ====================================================================== Common tasks: ------------- * cleaning: scons -c * build mandel: scons MODE=all mandel.nexe * some unittests: scons run_unit_tests * a smoke test: scons -k pp=1 smoke_test * 2nd smoke test: scons -k pp=1 MODE=nacl smoke_test * documentation: scons MODE=doc * firefox plugin: scons MODE=opt-linux npGoogleNaClPlugin * sel_ldr: scons MODE=opt-linux sel_ldr * firefox install: scons firefox_install Options: -------- pp=1 use command line pretty printing (more concise output) sdl=<mode> where <mode>: 'none': don't use SDL (default) 'local': use locally installed SDL 'hermetic': use the hermetic SDL copy naclsdk_mode=<mode> where <mode>: 'local': use locally installed sdk kit 'download': use the download copy (default) 'custom:<path>': use kit at <path> Automagically generated help: ----------------------------- Use --mode=type to specify the type of build to perform. The following types may be specified: dbg-mac MacOS debug build opt-mac MacOS optimized build nacl NaCl module build doc Documentation build The following build groups may also be specified via --mode. Build groups build one or more of the other build types. The available build groups are: all dbg-mac,opt-mac,nacl,doc default dbg-mac Multiple modes may be specified, separated by commas: --mode=mode1,mode2. If no mode is specified, the default group will be built. This is equivalent to specifying --mode=default. The following libraries can be built: gio naclthread nonnacl_util_c google_nacl_imc ncvalidate nrd_xfer google_nacl_imc_c ncvtest sel google_nacl_npruntime nonnacl_srpc gtest nonnacl_util all_libraries (do all of the above) The following large tests can be run: run_service_runtime_tests simple_tests run_large_tests (do all of the above) The following tests can be run: run_service_runtime_tests simple_tests run_all_tests (do all of the above) The following bundles can be built: /Users/amachang/nc/nacl/googleclient/native_client/scons-out/dbg-mac/staging/npGoogleNaClPlugin.bundle all_bundles (do all of the above) The following programs can be built: client ncval sel_universal nacl_cpuid npGoogleNaClPlugin server nacl_ldt_unittest npapi_test service_runtime_tests ncdecode_table nrd_xfer_test ncdis sel_ldr all_programs (do all of the above) Use scons -H for help about command-line options.
ãããããã®ãã¼ã«ã§ãªãã§ãä½ããã¿ããã§ããã
ãã£ãã Firefox ã®ãã©ã°ã¤ã³ãã¤ã³ã¹ãã¼ã«ãã¾ãã
$ ./scons --prebuilt firefox_install scons: Reading SConscript files ... ====================================================================== Building nexe binaries using sdk at [/Users/amachang/nc/nacl/googleclient/native_client/tools_bin/mac/sdk/nacl-sdk] ====================================================================== *** Solution file generation skipped (not supported on this platform). scons: done reading SConscript files. scons: Building targets ... /System/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python ./tools/firefoxinstall.py MODE=0 PLATFORM_BASE="/Users/amachang/nc/nacl/googleclient/native_client/scons-out/" MODE=0 PLATFORM_BASE=/Users/amachang/nc/nacl/googleclient/native_client/scons-out/ This script will install: /Users/amachang/nc/nacl/googleclient/native_client/scons-out/opt-mac/staging/npGoogleNaClPlugin.bundle in /Users/amachang/Library/Internet Plug-Ins/npGoogleNaClPlugin.bundle /Users/amachang/nc/nacl/googleclient/native_client/scons-out/opt-mac/staging/sel_ldr in /Users/amachang/Library/Internet Plug-Ins/npGoogleNaClPlugin.bundle/Contents/Resources and /Users/amachang/nc/nacl/googleclient/native_client/scons-out/opt-mac/Frameworks/SDL.framework in /Users/amachang/Library/Frameworks/SDL.framework Okey to continue? [y/n]
sel_ldr ã SDL.framework ã npGoogleNaClPlugin.bundle ãã¤ã³ã¹ãã¼ã«ãããè¦ããã§ããã
è¯ããã°ã y ã¨çãã¾ãã
Okey to continue? [y/n] y Okay, you asked for it. copying directory /Users/amachang/nc/nacl/googleclient/native_client/scons-out/opt-mac/staging/npGoogleNaClPlugin.bundle to /Users/amachang/Library/Internet Plug-Ins/npGoogleNaClPlugin.bundle ... copying directory /Users/amachang/nc/nacl/googleclient/native_client/scons-out/opt-mac/Frameworks/SDL.framework to /Users/amachang/Library/Frameworks/SDL.framework ... copying /Users/amachang/nc/nacl/googleclient/native_client/scons-out/opt-mac/staging/sel_ldr to /Users/amachang/Library/Internet Plug-Ins/npGoogleNaClPlugin.bundle/Contents/Resources ... ********************************************************************* * You have successfully installed the NaCl Firefox plugin. * As a self-test, please confirm you can run * /Users/amachang/Library/Internet Plug-Ins/npGoogleNaClPlugin.bundle/Contents/Resources/sel_ldr * from a shell/command prompt. With no args you should see * No nacl file specified * on Linux or Mac and no output on Windows. ********************************************************************* * To test this installation also try the test links on the page * scons-out/nacl/staging/index.html ********************************************************************* scons: done building targets.
ããããæåããã¿ããã§ãã
ãã©ã¦ã¶ã§ãµã³ãã«ãè¦ã¦ã¿ãã
ãã£ããã Firefox ãèµ·åãã¦ã scons-out/nacl/staging/earth.html ãè¦ã¦ã¿ã¾ãããã
ããããããããã£ã¡ã軽ãã§ãï¼
èªåã§åããã®ãä½ã£ã¦ã¿ã
ã§ã¯ããã£ããä½ãä½ã£ã¦ã¿ã¾ãããã
足ãç®ããã ãã® nexe ãä½ã£ã¦ã¿ã
ã¾ãã¯ã以ä¸ã®ãã㪠add.c ã¨ãããã¡ã¤ã«ãä½ãã¾ãã
#include <nacl/nacl_srpc.h> int Add(NaClAppArg **in_args, NaClAppArg **out_args) { out_args[0]->u.ival = in_args[0]->u.ival + in_args[1]->u.ival; return RPC_OK; } NACL_SRPC_METHOD("add:ii:i", Add);
次ã«ã以ä¸ã®ãã㪠add.html ãä½ãã¾ãã
<!DOCTYPE html> <html> <head> <title>test</title> </head> <body> <embed id="nacl" type="application/x-nacl-srpc" width="0" height="0" src="add.nexe" /> <a href="javascript:void(0);" onclick="alert(document.getElementById('nacl').add(1, 2))">1 + 2 = ?</a> </body> </html>
ã§ã以ä¸ã®ããã«ã³ã³ãã¤ã«ãã¾ãã
é·ã人㯠PATH ãéãã¦ãã¾ãã¾ãããã
$ nacl/googleclient/native_client/tools_bin/mac/sdk/nacl-sdk/bin/nacl-gcc -lsrpc -lgoogle_nacl_imc -lpthread -static add.c -o add.nexe
å®æãã¾ããã
ãã£ãããã©ã¦ã¶ã§è¦ã¦ã¿ã¾ãããã
ãããã足ãç®ãåºæ¥ã¾ããï¼
æååã® diff ãåã nexe ãä½ã£ã¦ã¿ã
http://labs.unoh.net/2008/11/diff_with_c.html ã§ç´¹ä»ããã¦ãã Google Code Archive - Long-term storage for Google Code Project Hosting. ã¨ãã diff ã©ã¤ãã©ãªã使ãã¾ãã
ã¾ãããã®ã©ã¤ãã©ãªã® dtl.hpp ãåããã£ã¬ã¯ããªã«ç½®ãã¾ãã
次ã«ã以ä¸ã®ãã㪠C++ ã®ã³ã¼ããæ¸ã diff.cpp ã¨ãã¾ãã
#include "dtl.hpp" #include <iostream> #include <vector> #include <sstream> #include <nacl/nacl_srpc.h> std::string diff(std::string as, std::string bs) { using namespace std; using namespace dtl; // æååãè¡ã«ãã©ã istringstream ais(as); istringstream bis(bs); string buf; vector<string> av, bv; while(getline(ais, buf)) av.push_back(buf); while(getline(bis, buf)) bv.push_back(buf); // Diff ãåã Diff<string, vector<string> > d(av, bv); d.compose(); Ses<string> ses = d.getSes(); vector< pair<string, elemInfo> > v = ses.getSequence(); // çµæã ostringstream ã« HTML å½¢å¼ã§åºåãã ostringstream os; vector< pair<string, elemInfo> >::iterator it; for (it = v.begin(); it != v.end(); ++it) { switch (it->second.type) { case SES_ADD : os << "<li class=\"add\">" << it->first << "</li>\n"; break; case SES_DELETE : os << "<li class=\"delete\">" << it->first << "</li>\n"; break; case SES_COMMON : os << "<li class=\"common\">" << it->first << "</li>\n"; break; default : break; } } return os.str(); } // SRPC ã§å¼ã³åºãããé¢æ° int Diff(NaClAppArg **in_args, NaClAppArg **out_args) { // diff é¢æ°ãå¼ã³åºã out_args[0]->u.sval = strdup(diff(in_args[0]->u.sval, in_args[1]->u.sval).c_str()); return RPC_OK; } // diff:ss:s ã¯ãæååãï¼ã¤åãåã£ã¦æååãè¿ãã¨ããæå³ NACL_SRPC_METHOD("diff:ss:s", Diff);
ããã¦ãããã»ã©ã¨åãããã«ã³ã³ãã¤ã«ãã¾ãã
$ nacl/googleclient/native_client/tools_bin/mac/sdk/nacl-sdk/bin/nacl-g++ -lsrpc -lgoogle_nacl_imc -lpthread -static diff.cpp -o diff.nexe
ä»å㯠C++ ãªã®ã§ nacl-g++ ã使ã£ã¦ããã¨ããã«æ³¨æãã¦ãã ããã
diff.nexe ãåºæ¥ãã®ã§ã以ä¸ã®ãã㪠diff.html ãä½ãã¾ãã
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Diff Sample</title> <style type="text/css"> html { width: 100%; margin: 0; padding 0; } body { width: 96%; margin: 2%; padding 0; } body > div { float: left; width: 50%; } body > div > textarea { width: 90%; height: 10em; } ul { list-style-type: none; margin: 0; padding: 0 } li { white-space: pre } li.add { color: #080; background: #8f8; } li.delete { color: #800; background: #f88; } </style> <script type="text/javascript"> var result, nacl, text1, text2; window.onload = function() { result = document.getElementById('result'); nacl = document.getElementById('nacl'); text1 = document.getElementById('text1'); text2 = document.getElementById('text2'); }; </script> </head> <body> <h1>Diff Sample</h1> <div> <h2>Text 1</h2> <textarea id="text1"> function fib(n){ if(n == 1 || n == 2){ return 1; }else{ return fib(n - 1) + fib(n - 2); } } </textarea> </div> <div> <h2>Text 2</h2> <textarea id="text2"> function fibonatti(n){ if(n == 1 || n == 2){ return 1; }else{ return fibonatti(n - 1) + fibonatti(n - 2); } } </textarea> </div> <p> <a href="javascript:void(0);" onclick="result.innerHTML = nacl.diff(text1.value, text2.value);">diff!</a> </p> <ul id="result"></ul> <embed id="nacl" type="application/x-nacl-srpc" width="0" height="0" src="diff.nexe" /> </body> </html>
ããã¦ããã©ã¦ã¶ã§èªã¿è¾¼ãã¨ããã
ããããããã diff ãåãã¾ããï¼
èªå㧠Native Client ã®å®è¡ç°å¢ããã«ããã¦ã¿ã
ãã£ãã clean ãã¦
$ ./scons --mode=dbg-mac,nacl - c
ãããã°ãã«ããã¾ãã
$ ./scons --mode=dbg-mac,nacl
æ®éã«æåãã¾ããã
ã§ã firefox ã«ãããã°çãã¤ã³ã¹ãã¼ã«ãã¾ãã
$ ./scons firefox_install DBG=1
ã§ããã©ããã£ãããããã°ã§ãããã ãã orz
ããã¥ã¡ã³ãã«ã¯ã以ä¸ã®ããã«ã¤ã³ã¯ã«ã¼ããã¦ãæ®éã®ãã¼ã«ã«ã¢ããªã±ã¼ã·ã§ã³ã¨ãã¦ãã«ãããã°ã gdb ã§ã kdbg ã§ããªãã§ãåºæ¥ãããï¼ã¨ãããããªãã¨ãæ¸ãã¦ããã¾ããã
#if !defined(STANDALONE) #include <nacl/nacl_srpc.h> #else #include "native_client/common/standalone.h" #endif
ã©ããã£ã¦ nexe ã¯å®è¡ãããã
ã¡ãã£ã¨èª¿ã¹ã¦ã¿ã¾ãã
sel_ldr ãå¥ããã»ã¹ã¨ãã¦ç«ã¡ä¸ãã£ã¦ã
$ ps auwx | grep sel_ldr amachang 17617 0.0 0.3 1139488 6256 ?? S 8:50PM 0:00.12 /Users/amachang/Library/Internet Plug-Ins/npGoogleNaClPlugin.bundle/Contents/Resources/sel_ldr -f /Users/amachang/nc/sample/diff/diff.nexe -i 5:42 -P 5 -X 5
ãã¼ã¸ããã¼ããããã¨ã«ãä¸ã¤ sel_ldr ããã»ã¹ãç«ã¡ä¸ããã¿ããã§ãã
ãã㨠Firefox ãã©ãã«ãéä¿¡ãã¦ãããã§ããã
ã©ããã£ã¦ã nexe ã«ã¸ã£ã³ãããã
service_runtime/nacl_switch.S ã¨ããã¢ã»ã³ãã©ããã£ã¦ã以ä¸ã®ããã«ã¸ã£ã³ããã¦ãã¾ãã
.text .globl IDENTIFIER(NaClSwitch) IDENTIFIER(NaClSwitch): popl %eax /* throw away the return addr */ /* do not leak info to app */ xorl %ecx, %ecx /* xorl will leave eflags in a known state, so no info leaks */ popl %edx /* new eip */ popl %ebp popl %edi popl %esi popl %ebx popl %gs popl %fs popl %es ljmp *(%esp)
é£ãã å ã¯ã©ããªã£ã¦ããã
diff.cpp ã«ã¯ main ãããã¾ããã§ãããã©ãã«é£ã¶ã®ã§ããããã
libsrpc.a ã« main ã weak ã·ã³ãã«ã§å®ç¾©ããã¦ãã¾ããã
int __attribute__ ((weak)) main(int argc, char* argv[]) { /* * Print the methods that are available. __NaClPrintRpcMethods(); */ srpc_init(); /* * Message processing loop goes here. For now, just do a sel_universal. */ __CommandLoop(); return 0; }
ã§ã¯ __CommandLoop ã§ã¯ä½ããã£ã¦ããã®ã§ããããã
__CommandLoop ã§ã¯ä½ããã£ã¦ããã®ã
__CommandLoop ã¯ä»¥ä¸ã®ããã«ãªã£ã¦ãã¾ããã
NaClSrpcError __CommandLoop() { ï¼ ï¼ socket_desc = __srpc_get_fd(); if (socket_desc == -1) { /* * No socket connection, use stdin/stdout. */ rpc_desc = __BuildInterfaceDescription(&num_rpc); // process commands from stdin and dispatch for (;;) { ï¼ ï¼ } } else { NaClSrpcChannel channel; ï¼ ï¼ for (;;) { ï¼ ï¼ } ï¼ ï¼ } return RPC_OK; }
ã³ã¡ã³ããè¦ãéãã¯ãã½ã±ããéä¿¡ãã¦ãããã©ããã§ã«ã¼ããåãã¦ãã¾ãã
SRPC ã¡ãã»ã¼ã¸ã®ãã©ã¼ãããã¯ï¼
tools/libsrpc/rpc_serialize.c ã®ã³ã¡ã³ãã®ã¨ããã«æ¸ãã¦ããã¾ãã
SRPC ã®è§£æå¦ç â é¢æ°å®è¡ã®æµã
Firefox ãããã¼ã¿ãéããã¦ãã㨠tools/libsrpc/rpc_serialize.c ã®ä»¥ä¸ã®ç®æ㧠rpc_number ãæ½åºãã
ï¼ retval = ImcRead(&client_protocol, sizeof(client_protocol), 1, channel); ï¼ retval = ImcRead(&rpc_number, sizeof(rpc_number), 1, channel); ï¼
以ä¸ã®ç®æã§ãå®éã«ã¢ããªã±ã¼ã·ã§ã³ã«æ¸ãããããã®é¢æ°ï¼ãã£ãã®ä¾ã® Add ã Diffï¼ãå¼ã³åºããã¾ãã
app_error = (channel->rpc_descr[rpc_number].handler)(args, rets);
ã¾ãããã¼ã¸é·ç§»ãã㨠Firefox ãã NACL_SRPC_SHUTDOWN_METHOD ã¨ããã¡ãã»ã¼ã¸ãéããã¦ãã¦
以ä¸ã® SRPC ã®ã¡ã½ãããå¼ã°ãã nexe ã¯çµäºãã¾ãã
static int srpc_shutdown_request(NaClAppArg **in_args, NaClAppArg **out_arg) { if (srpc_privileged) { _exit(0); } return RPC_OK; } NACL_SRPC_METHOD("shutdown::", srpc_shutdown_request);
ãã®ã¡ãã»ã¼ã¸ï¼NACL_SRPC_SHUTDOWN_METHODï¼ã¯ã JavaScript ããã element.shutdown() ã¨ããããã«å¼ã³åºããã¨ã§éåºãããã¨ãåºæ¥ã¾ãã
ã¾ã¨ã
ããããã¾ã¨ãã¾ããã£ã¨ãã¨ãããã試ãã¦ã¿ã Native Client ã§ãããã¡ãã£ã¨é£ããã£ãã§ãï¼ï¼
ã§ãããã¤ãã£ãã®ã³ã¼ããåãã¨ããã®ã¯ãã£ã±ãåãã§ããã
Alchemy ã®ãããªã¢ããã¼ãã§ã¯ï¼C â LLVM â AS â ABC ã¨ããæãï¼ããã¯ãé度ã«ã¯éçãããã¾ããã
ãã ãã»ãã¥ãªãã£ãã©ããã£ã¦ç¢ºä¿ãã¦ããã®ããæ°ã«ãªãã¾ããããã¡ãããã¦ã§ããã¼ã¸ã«åãè¾¼ããããªãã®ãªã®ã§ãã¡ãã¨ãããµã³ãããã¯ã¹ãå¿
è¦ã§ããããæéãããã¨ãã«ãããã辺ã調ã¹ã¦ã¿ããã§ããã
ãããã»ãã¥ãªãã£ä¸åé¡ããªãã®ãªãããã以ä¸æå¼·ãªãã®ã¯ãªãã®ã§ã¯ãªãã§ããããã
追è¨ï¼id:moira ãããããã辺ã®ãã¨ã«è¨åããã¦ãã¾ã
http://blog.deadbeaf.org/2008/12/09/google-native-client/
ãããã§ãï¼ï¼