Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Imports Ruby's port to NativeClient (a.k.a NaCl).

Patch by Google Inc. [ruby-core:45073].

* configure.in (RUBY_NACL): New M4 func to configure variables for
  NaCl.
  (RUBY_NACL_CHECK_PEPPER_TYPES): New M4 func to check the old names
  of Pepper interface types.
  (BTESTRUBY): New variable to specify which ruby should be run on
  "make btest". NaCl can run the built binary by sel_ldr, but it need
  rbconfig.rb. So this variable is distinguished from $MINIRUBY.
  
* thread_pthread.c: Disabled some features on NaCl.

* io.c: ditto.

* process.c: ditto.

* signal.c: ditto.

* file.c: ditto.

* missing/flock.c: ditto.

* nacl/pepper_main.c: An example implementation of Pepper application
  that embeds Ruby.

* nacl/example.html: An example of web page that uses the Pepper
  application.

* nacl/nacl-config.rb: Detects variants of NaCl SDK.

* nacl/GNUmakefile.in: Makefile template for NaCl specific build
  process.

* nacl/package.rb: script for packaging a NaCl-Ruby embedding
  application. 

* nacl/reate_nmf.rb: Wrapper script of create_nmf.py

* dln.c (dln_load): Added a hack to call on NaCl.

* util.c (ruby_getcwd): Path to the current directort is not available
  on NaCl.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit 76bc2d1ed7f13fb329c33f48756ea3c24c59a6ea 1 parent 0a7aada
Yuki Sonoda (Yugui) authored
49  ChangeLog
... ...
@@ -1,6 +1,53 @@
  1
+Thu May 17 11:33:07 2012  Yuki Yugui Sonoda  <yugui@google.com>
  2
+
  3
+	Imports Ruby's port to NativeClient (a.k.a NaCl).
  4
+	Patch by Google Inc. [ruby-core:45073].
  5
+
  6
+	* configure.in (RUBY_NACL): New M4 func to configure variables for
  7
+	  NaCl.
  8
+	  (RUBY_NACL_CHECK_PEPPER_TYPES): New M4 func to check the old names
  9
+	  of Pepper interface types.
  10
+	  (BTESTRUBY): New variable to specify which ruby should be run on
  11
+	  "make btest". NaCl can run the built binary by sel_ldr, but it need
  12
+	  rbconfig.rb. So this variable is distinguished from $MINIRUBY.
  13
+	  
  14
+	* thread_pthread.c: Disabled some features on NaCl.
  15
+
  16
+	* io.c: ditto.
  17
+
  18
+	* process.c: ditto.
  19
+
  20
+	* signal.c: ditto.
  21
+
  22
+	* file.c: ditto.
  23
+
  24
+	* missing/flock.c: ditto.
  25
+
  26
+	* nacl/pepper_main.c: An example implementation of Pepper application
  27
+	  that embeds Ruby.
  28
+
  29
+	* nacl/example.html: An example of web page that uses the Pepper
  30
+	  application.
  31
+
  32
+	* nacl/nacl-config.rb: Detects variants of NaCl SDK.
  33
+
  34
+	* nacl/GNUmakefile.in: Makefile template for NaCl specific build
  35
+	  process.
  36
+
  37
+	* nacl/package.rb: script for packaging a NaCl-Ruby embedding
  38
+	  application. 
  39
+
  40
+	* nacl/reate_nmf.rb: Wrapper script of create_nmf.py
  41
+
  42
+	* dln.c (dln_load): Added a hack to call on NaCl.
  43
+
  44
+	* util.c (ruby_getcwd): Path to the current directort is not available
  45
+	  on NaCl.
  46
+
1 47
 Thu May 17 10:54:58 2012  Nobuyoshi Nakada  <nobu@ruby-lang.org>
2 48
 
3  
-	* ext/tk/extconf.rb: add -l options to $libs not $LDFLAGS, to be
  49
+	* ext/tk/extconf.rb: add -l options to $libs not $LDFLAGS,
  50
+	to be
4 51
 	  passed to EXTLIBS in exts.mk.
5 52
 
6 53
 	* enc/encinit.c.erb: use %-lines to adjust indent in the generated file.
2  Makefile.in
@@ -90,6 +90,8 @@ MINIRUBY = @MINIRUBY@\
90 90
 	$(MINIRUBYOPT)
91 91
 RUNRUBY = @RUNRUBY@ $(RUNRUBYOPT) -- $(RUN_OPTS)
92 92
 XRUBY = @XRUBY@
  93
+BTESTRUBY = @BTESTRUBY@\
  94
+	$(MINIRUBYOPT)
93 95
 INSTALL = @INSTALL@
94 96
 INSTALL_DATA = @INSTALL_DATA@
95 97
 INSTALL_SCRIPT = @INSTALL_SCRIPT@
2  common.mk
@@ -472,7 +472,7 @@ check-ruby: test test-ruby
472 472
 btest: $(TEST_RUNNABLE)-btest
473 473
 no-btest: PHONY
474 474
 yes-btest: miniruby$(EXEEXT) PHONY
475  
-	$(BOOTSTRAPRUBY) "$(srcdir)/bootstraptest/runner.rb" --ruby="$(MINIRUBY)" $(OPTS)
  475
+	$(BOOTSTRAPRUBY) "$(srcdir)/bootstraptest/runner.rb" --ruby="$(BTESTRUBY)" $(OPTS)
476 476
 
477 477
 btest-ruby: $(TEST_RUNNABLE)-btest-ruby
478 478
 no-btest-ruby: PHONY
130  configure.in
@@ -51,6 +51,79 @@ target_cpu=x64
51 51
 ])
52 52
 ])
53 53
 
  54
+AC_DEFUN([RUBY_NACL],
  55
+[
  56
+ AS_CASE(["${host_os}"], 
  57
+[nacl], [
  58
+  ac_cv_exeext=.nexe
  59
+  host_vendor=chromium
  60
+  ac_cv_host=chromium
  61
+  AC_MSG_CHECKING([wheather \$NACL_SDK_ROOT is set])
  62
+  if test x"${NACL_SDK_ROOT}" = x; then
  63
+    AC_MSG_RESULT([no])
  64
+    AC_MSG_ERROR([You need to set \$NACL_SDK_ROOT environment variable to build for NativeClient])
  65
+  fi
  66
+  AC_MSG_RESULT([yes])
  67
+
  68
+  nacl_cv_build_variant=glibc
  69
+  AC_ARG_WITH(newlib,
  70
+              AS_HELP_STRING([--with-newlib], [uses newlib version of NativeClient SDK]),
  71
+              [AS_CASE([$withval],
  72
+                       [no], [nacl_cv_build_variant=glibc],
  73
+                       [yes], [nacl_cv_build_variant=newlib])])
  74
+
  75
+  AS_CASE(["$build_cpu"],
  76
+          [x86_64|i?86], [nacl_cv_cpu_nick=x86], [nacl_cv_cpu_nick=$build_cpu])
  77
+  AS_CASE(["$build_os"],
  78
+          [linux*], [nacl_cv_os_nick=linux],
  79
+          [darwin*], [nacl_cv_os_nick=mac],
  80
+          [cygwin*|mingw*], [nacl_cv_os_nick=win],
  81
+          [nacl_cv_os_nick=$build_os])
  82
+
  83
+  host="$host_cpu-chromium-$host_os-"
  84
+  ac_tool_prefix="$host_cpu-nacl-"
  85
+
  86
+  AC_MSG_CHECKING([NativeClient toolchain])
  87
+  if test -d \
  88
+    "${NACL_SDK_ROOT}/toolchain/${nacl_cv_os_nick}_${nacl_cv_cpu_nick}_${nacl_cv_build_variant}"; then
  89
+    NACL_TOOLCHAIN="${nacl_cv_os_nick}_${nacl_cv_cpu_nick}_${nacl_cv_build_variant}"
  90
+  else
  91
+    AS_CASE(
  92
+      ["${nacl_cv_build_variant}"],
  93
+      [glibc], [if test \
  94
+        -d "${NACL_SDK_ROOT}/toolchain/${nacl_cv_os_nick}_${nacl_cv_cpu_nick}_newlib" \
  95
+        -a -d "${NACL_SDK_ROOT}/toolchain/${nacl_cv_os_nick}_${nacl_cv_cpu_nick}"; then
  96
+        NACL_TOOLCHAIN="${nacl_cv_os_nick}_${nacl_cv_cpu_nick}"
  97
+      fi],
  98
+      [newlib], [ NACL_TOOLCHAIN="${nacl_cv_os_nick}_${nacl_cv_cpu_nick}" ])
  99
+  fi
  100
+  if test ! -e "${NACL_SDK_ROOT}/toolchain/${NACL_TOOLCHAIN}/${ac_tool_prefix}gcc"; then
  101
+    if test "${build_cpu}" = i686 -a -e "${NACL_SDK_ROOT}/toolchain/${NACL_TOOLCHAIN}/nacl-gcc"; then
  102
+      ac_tool_prefix=nacl-
  103
+    fi
  104
+    if test "${build_cpu}" = x86_64 -a -e "${NACL_SDK_ROOT}/toolchain/${NACL_TOOLCHAIN}/nacl-gcc"; then
  105
+      ac_tool_prefix=nacl64-
  106
+    fi
  107
+  fi
  108
+  if test -z "${NACL_TOOLCHAIN}"; then
  109
+    AC_MSG_ERROR([Unrecognized --host and --build combination or NaCl SDK is not installed])
  110
+  fi
  111
+  PATH="${PATH}:${NACL_SDK_ROOT}/toolchain/${NACL_TOOLCHAIN}/bin"
  112
+  AC_MSG_RESULT(${NACL_TOOLCHAIN})
  113
+
  114
+  AC_SUBST(NACL_TOOLCHAIN)
  115
+  AC_SUBST(NACL_SDK_ROOT)
  116
+  AC_SUBST(NACL_SDK_VARIANT, nacl_cv_build_variant)
  117
+])])
  118
+
  119
+AC_DEFUN([RUBY_NACL_CHECK_PEPPER_TYPES],
  120
+[
  121
+ AC_CHECK_TYPES([struct PPB_Core, struct PPB_Messaging, struct PPB_Var,
  122
+              struct PPB_URLLoader, struct PPB_URLRequestInfo,
  123
+              struct PPB_URLResponseInfo, struct PPB_FileRef,
  124
+              struct PPP_Instance])
  125
+])
  126
+
54 127
 AC_DEFUN([RUBY_CPPOUTFILE],
55 128
 [AC_CACHE_CHECK(whether ${CPP} accepts -o, rb_cv_cppoutfile,
56 129
 [cppflags=$CPPFLAGS
@@ -283,6 +356,7 @@ if test -z "${CXXFLAGS+set}"; then
283 356
     cxxflags="$cxxflags "'${optflags} ${debugflags} ${warnflags}'
284 357
 fi
285 358
 
  359
+RUBY_NACL
286 360
 if test x"${build}" != x"${host}"; then
287 361
   AC_CHECK_TOOL(CC, gcc)
288 362
 fi
@@ -377,6 +451,7 @@ AC_SUBST(MAKEDIRS)
377 451
 
378 452
 AC_CHECK_PROGS(DOT, dot)
379 453
 AC_CHECK_PROGS(DOXYGEN, doxygen)
  454
+AS_CASE(["${host_os}"], [nacl], [AC_PATH_PROG(PYTHON, python)])
380 455
 
381 456
 AC_CHECK_PROG(PKG_CONFIG, pkg-config, [pkg-config], [], [],
382 457
     [`"$as_dir/$ac_word$ac_exec_ext" --print-errors --version > /dev/null 2>&1 || echo "$as_dir/$ac_word$ac_exec_ext"`])
@@ -509,7 +584,7 @@ if test "$GCC" = yes; then
509 584
 
510 585
     # -fstack-protector
511 586
     AS_CASE(["$target_os"],
512  
-    [mingw*], [
  587
+    [mingw*|nacl], [
513 588
 	stack_protector=no
514 589
     ],
515 590
     [
@@ -1135,6 +1210,14 @@ main()
1135 1210
 		],
1136 1211
 [superux*], [	ac_cv_func_setitimer=no
1137 1212
 		],
  1213
+[nacl], [
  1214
+  LIBS="-lm -lnosys $LIBS"
  1215
+  if test "${nacl_cv_build_variant}" = "newlib"; then
  1216
+    RUBY_APPEND_OPTION(CPPFLAGS, -DNACL_NEWLIB)
  1217
+  else
  1218
+    RUBY_APPEND_OPTION(XCFLAGS, -fPIC)
  1219
+  fi
  1220
+  ],
1138 1221
 [	LIBS="-lm $LIBS"])
1139 1222
 AC_CHECK_LIB(crypt, crypt)
1140 1223
 AC_CHECK_LIB(dl, dlopen)	# Dynamic linking for SunOS/Solaris and SYSV
@@ -1201,6 +1284,9 @@ AC_CHECK_MEMBERS([struct stat.st_ctimensec])
1201 1284
 
1202 1285
 AC_CHECK_TYPES([struct timespec], [], [], [@%:@ifdef HAVE_TIME_H
1203 1286
 @%:@include <time.h>
  1287
+@%:@endif
  1288
+@%:@ifdef HAVE_SYS_TIME_H
  1289
+@%:@include <sys/time.h>
1204 1290
 @%:@endif])
1205 1291
 
1206 1292
 AC_CHECK_TYPES([struct timezone], [], [], [@%:@ifdef HAVE_TIME_H
@@ -1263,6 +1349,8 @@ RUBY_DEFINT(intptr_t, void*)
1263 1349
 RUBY_DEFINT(uintptr_t, void*, unsigned)
1264 1350
 RUBY_DEFINT(ssize_t, size_t, [], [@%:@include <sys/types.h>])	dnl may differ from int, so not use AC_TYPE_SSIZE_T.
1265 1351
 
  1352
+RUBY_NACL_CHECK_PEPPER_TYPES
  1353
+
1266 1354
 AC_CACHE_CHECK(for stack end address, rb_cv_stack_end_address,
1267 1355
 [rb_cv_stack_end_address=no
1268 1356
 for addr in __libc_stack_end _SEND; do
@@ -1451,11 +1539,11 @@ AC_CHECK_FUNCS(fmod killpg wait4 waitpid fork spawnv syscall __syscall chroot ge
1451 1539
 	      getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
1452 1540
 	      getpriority getrlimit setrlimit sysconf close getpwnam_r getgrnam_r\
1453 1541
 	      dlopen sigprocmask sigaction sigsetjmp _setjmp _longjmp\
1454  
-	      setsid telldir seekdir fchmod cosh sinh tanh log2 round\
  1542
+	      setsid telldir seekdir fchmod cosh sinh tanh log2 round llabs\
1455 1543
 	      setuid setgid daemon select_large_fdset setenv unsetenv\
1456 1544
               mktime timegm gmtime_r clock_gettime gettimeofday poll ppoll\
1457 1545
               pread sendfile shutdown sigaltstack dl_iterate_phdr\
1458  
-              dup3 pipe2 posix_memalign memalign)
  1546
+              dup3 pipe2 posix_memalign memalign ioctl)
1459 1547
 
1460 1548
 AC_CACHE_CHECK(for unsetenv returns a value, rb_cv_unsetenv_return_value,
1461 1549
   [AC_TRY_COMPILE([
@@ -1917,7 +2005,8 @@ if test x"$enable_pthread" = xyes; then
1917 2005
 	pthread_getattr_np pthread_attr_get_np pthread_attr_getstack\
1918 2006
 	pthread_get_stackaddr_np pthread_get_stacksize_np \
1919 2007
 	thr_stksegment pthread_stackseg_np pthread_getthrds_np \
1920  
-	pthread_condattr_setclock pthread_sigmask)
  2008
+        pthread_cond_initialize pthread_condattr_setclock pthread_condattr_init \
  2009
+        pthread_sigmask)
1921 2010
 fi
1922 2011
 if test x"$ac_cv_header_ucontext_h" = xyes; then
1923 2012
     if test x"$rb_with_pthread" = xyes; then
@@ -2034,11 +2123,14 @@ if test "$rb_cv_binary_elf" = yes; then
2034 2123
   if test "$with_dln_a_out" = yes; then
2035 2124
     AC_MSG_ERROR(dln_a_out does not work with ELF)
2036 2125
   fi
2037  
-  AC_LIBOBJ([addr2line])
  2126
+  AC_CHECK_HEADERS([elf.h elf_abi.h])
  2127
+  if test $ac_cv_header_elf_h = yes -o $ac_cv_header_elf_abi_h = yes; then
  2128
+    AC_LIBOBJ([addr2line])
  2129
+  fi
2038 2130
 fi
2039 2131
 
2040 2132
 AS_CASE(["$target_os"],
2041  
-[linux* | gnu* | k*bsd*-gnu | bsdi* | kopensolaris*-gnu], [
  2133
+[linux* | gnu* | k*bsd*-gnu | bsdi* | kopensolaris*-gnu | nacl], [
2042 2134
     if test "$rb_cv_binary_elf" = no; then
2043 2135
 	with_dln_a_out=yes
2044 2136
     else
@@ -2218,6 +2310,7 @@ if test "$with_dln_a_out" != yes; then
2218 2310
 			rb_cv_dlopen=yes],
2219 2311
 	[os2-emx*], [	LDFLAGS="$LDFLAGS -Zomf"
2220 2312
 			],
  2313
+        [nacl], [ LDSHARED='$(CC) -shared' ],
2221 2314
 	[ 	: ${LDSHARED='$(LD)'}])
2222 2315
   AC_MSG_RESULT($rb_cv_dlopen)
2223 2316
 fi
@@ -2342,6 +2435,9 @@ AS_CASE(["$target_os"],
2342 2435
   [*djgpp*], [
2343 2436
     setup=Setup.dj
2344 2437
     ],
  2438
+  [nacl], [
  2439
+    setup=Setup.nacl
  2440
+    ],
2345 2441
   [
2346 2442
     setup=Setup
2347 2443
     ])
@@ -2352,6 +2448,7 @@ if test "$prefix" = NONE; then
2352 2448
   prefix=$ac_default_prefix
2353 2449
 fi
2354 2450
 
  2451
+BTESTRUBY='$(MINIRUBY)'
2355 2452
 if test x"$cross_compiling" = xyes; then
2356 2453
   test x"$MINIRUBY" = x && MINIRUBY="${RUBY-$BASERUBY} -I`pwd` "-r'$(arch)-fake'
2357 2454
   XRUBY_LIBDIR=`${RUBY-$BASERUBY} -rrbconfig -e ['puts RbConfig::CONFIG["libdir"]']`
@@ -2364,6 +2461,20 @@ if test x"$cross_compiling" = xyes; then
2364 2461
   RUNRUBY='$(MINIRUBY) -I`cd $(srcdir)/lib; pwd`'
2365 2462
   XRUBY='$(MINIRUBY)'
2366 2463
   TEST_RUNNABLE=no
  2464
+
  2465
+  if test "$host_os" = "nacl"; then 
  2466
+      if test "$build_cpu" = "$host_cpu" || test "${nacl_cv_cpu_nick}" = "x86" -a "$host_cpu" = "i686"; then
  2467
+          nacl_cv_sel_ldr='`$(MINIRUBY) $(srcdir)/nacl/nacl-config.rb sel_ldr`'
  2468
+          nacl_cv_irt_core='`$(MINIRUBY) $(srcdir)/nacl/nacl-config.rb irt_core`'
  2469
+          nacl_cv_runnable_ld='`$(MINIRUBY) $(srcdir)/nacl/nacl-config.rb runnable_ld`'
  2470
+          nacl_cv_host_lib='`$(MINIRUBY) $(srcdir)/nacl/nacl-config.rb host_lib`'
  2471
+          TEST_RUNNABLE=yes
  2472
+          BTESTRUBY="${nacl_cv_sel_ldr} -a -B ${nacl_cv_irt_core} -w 1:3 -w 2:4"
  2473
+          BTESTRUBY="$BTESTRUBY -- ${nacl_cv_runnable_ld} --library-path ${nacl_cv_host_lib}"
  2474
+          BTESTRUBY="$BTESTRUBY `pwd`/"'miniruby$(EXEEXT) -I`cd $(srcdir)/lib; pwd` -I.'
  2475
+          BTESTRUBY="$BTESTRUBY"' -I$(EXTOUT)/common 3>&1 4>&2 1>/dev/null 2>/dev/null '
  2476
+      fi
  2477
+  fi
2367 2478
 else
2368 2479
   MINIRUBY='./miniruby$(EXEEXT) -I$(srcdir)/lib -I.'
2369 2480
   MINIRUBY="$MINIRUBY"' -I$(EXTOUT)/common'
@@ -2374,6 +2485,7 @@ else
2374 2485
 fi
2375 2486
 AC_SUBST(TEST_RUNNABLE)
2376 2487
 AC_SUBST(MINIRUBY)
  2488
+AC_SUBST(BTESTRUBY)
2377 2489
 AC_SUBST(PREP)
2378 2490
 AC_SUBST(RUNRUBY)
2379 2491
 AC_SUBST(XRUBY)
@@ -2600,6 +2712,7 @@ AC_CACHE_CHECK([for prefix of external symbols], rb_cv_symbol_prefix, [
2600 2712
 SYMBOL_PREFIX="$rb_cv_symbol_prefix"
2601 2713
 test "x$SYMBOL_PREFIX" = xNONE && SYMBOL_PREFIX=''
2602 2714
 MINIDLNOBJ=dmydln.o
  2715
+
2603 2716
 AS_CASE(["$target_os"],
2604 2717
     [linux*], [
2605 2718
 	],
@@ -2679,7 +2792,10 @@ AS_CASE(["$target_os"],
2679 2792
 	AS_CASE(["$YACC"],[*yacc*], [
2680 2793
 	    XCFLAGS="$XCFLAGS -DYYMAXDEPTH=300"
2681 2794
 	    YACC="$YACC -Nl40000 -Nm40000"
2682  
-	])])
  2795
+	])],
  2796
+    [nacl], [
  2797
+	FIRSTMAKEFILE=GNUmakefile:nacl/GNUmakefile.in
  2798
+	])
2683 2799
 MINIOBJS="$MINIDLNOBJ"
2684 2800
 
2685 2801
 AS_CASE(["$THREAD_MODEL"],
4  dir.c
@@ -44,6 +44,10 @@
44 44
 #  include "win32/dir.h"
45 45
 # endif
46 46
 #endif
  47
+#if defined(__native_client__) && defined(NACL_NEWLIB)
  48
+# include "nacl/dirent.h"
  49
+# include "nacl/stat.h"
  50
+#endif
47 51
 
48 52
 #include <errno.h>
49 53
 
15  dln.c
@@ -1318,13 +1318,28 @@ dln_load(const char *file)
1318 1318
 # define RTLD_GLOBAL 0
1319 1319
 #endif
1320 1320
 
  1321
+#ifdef __native_client__
  1322
+	char* p, *orig;
  1323
+        if (file[0] == '.' && file[1] == '/') file+=2;
  1324
+	orig = strdup(file);
  1325
+	for (p = file; *p; ++p) {
  1326
+	    if (*p == '/') *p = '_';
  1327
+	}
  1328
+#endif
1321 1329
 	/* Load file */
1322 1330
 	if ((handle = (void*)dlopen(file, RTLD_LAZY|RTLD_GLOBAL)) == NULL) {
  1331
+#ifdef __native_client__
  1332
+            free(orig);
  1333
+#endif
1323 1334
 	    error = dln_strerror();
1324 1335
 	    goto failed;
1325 1336
 	}
1326 1337
 
1327 1338
 	init_fct = (void(*)())(VALUE)dlsym(handle, buf);
  1339
+#ifdef __native_client__
  1340
+	strcpy(file, orig);
  1341
+	free(orig);
  1342
+#endif
1328 1343
 #if defined __SYMBIAN32__
1329 1344
 	if (init_fct == NULL) {
1330 1345
 	    init_fct = (void(*)())dlsym(handle, "1"); /* Some Symbian versions do not support symbol table in DLL, ordinal numbers only */
50  ext/Setup.nacl
... ...
@@ -0,0 +1,50 @@
  1
+# #option nodynamic
  2
+# 
  3
+# #Win32API
  4
+# bigdecimal
  5
+# continuation
  6
+# coverage
  7
+# #curses
  8
+# date
  9
+# #dbm
  10
+# digest/bubblebabble
  11
+# digest
  12
+# digest/md5
  13
+# digest/rmd160
  14
+# digest/sha1
  15
+# digest/sha2
  16
+# dl
  17
+# dl/callback
  18
+# #dl/win32
  19
+# etc
  20
+# fcntl
  21
+# fiber
  22
+# #fiddle
  23
+# #gdbm
  24
+# #iconv
  25
+# io/console
  26
+# io/nonblock
  27
+# io/wait
  28
+# #json
  29
+# json/generator
  30
+# json/parser
  31
+# mathn/complex
  32
+# mathn/rational
  33
+# nkf
  34
+# objspace
  35
+# #openssl
  36
+# pathname
  37
+# #psych
  38
+# #pty
  39
+# racc/cparse
  40
+# #readline
  41
+# ripper
  42
+# #sdbm
  43
+# #socket
  44
+# stringio
  45
+# strscan
  46
+# syck
  47
+# #syslog
  48
+# #tk
  49
+# #tk/tkutil
  50
+# #zlib
2  ext/extmk.rb
@@ -530,7 +530,7 @@ def initialize(src)
530 530
   list = $extlist.dup
531 531
   built = []
532 532
   while e = list.shift
533  
-    s,t,i,r = e
  533
+    s,t,i,r,os = e
534 534
     if r and !(r -= built).empty?
535 535
       l = list.size
536 536
       if (while l > 0; break true if r.include?(list[l-=1][1]) end)
2  ext/pty/extconf.rb
... ...
@@ -1,6 +1,6 @@
1 1
 require 'mkmf'
2 2
 
3  
-if /mswin|mingw|bccwin/ !~ RUBY_PLATFORM
  3
+if /mswin|mingw|bccwin|nacl/ !~ RUBY_PLATFORM
4 4
   have_header("sys/stropts.h")
5 5
   have_func("setresuid")
6 6
   have_header("libutil.h")
22  file.c
@@ -60,6 +60,13 @@ int flock(int, int);
60 60
 #include <sys/types.h>
61 61
 #include <sys/stat.h>
62 62
 
  63
+#if defined(__native_client__) && defined(NACL_NEWLIB)
  64
+# include "nacl/utime.h"
  65
+# include "nacl/stat.h"
  66
+# include "nacl/unistd.h"
  67
+#endif
  68
+
  69
+
63 70
 #ifdef HAVE_SYS_MKDEV_H
64 71
 #include <sys/mkdev.h>
65 72
 #endif
@@ -3358,7 +3365,11 @@ realpath_rec(long *prefixlenp, VALUE *resolvedp, const char *unresolved, VALUE l
3358 3365
                 struct stat sbuf;
3359 3366
                 int ret;
3360 3367
                 VALUE testpath2 = rb_str_encode_ospath(testpath);
  3368
+#ifdef __native_client__
  3369
+                ret = stat(RSTRING_PTR(testpath2), &sbuf);
  3370
+#else
3361 3371
                 ret = lstat(RSTRING_PTR(testpath2), &sbuf);
  3372
+#endif
3362 3373
                 if (ret == -1) {
3363 3374
                     if (errno == ENOENT) {
3364 3375
                         if (strict || !last || *unresolved_firstsep)
@@ -3403,6 +3414,13 @@ realpath_rec(long *prefixlenp, VALUE *resolvedp, const char *unresolved, VALUE l
3403 3414
     }
3404 3415
 }
3405 3416
 
  3417
+#ifdef __native_client__
  3418
+VALUE
  3419
+rb_realpath_internal(VALUE basedir, VALUE path, int strict)
  3420
+{
  3421
+    return path;
  3422
+}
  3423
+#else
3406 3424
 VALUE
3407 3425
 rb_realpath_internal(VALUE basedir, VALUE path, int strict)
3408 3426
 {
@@ -3476,6 +3494,7 @@ rb_realpath_internal(VALUE basedir, VALUE path, int strict)
3476 3494
     OBJ_TAINT(resolved);
3477 3495
     return resolved;
3478 3496
 }
  3497
+#endif
3479 3498
 
3480 3499
 /*
3481 3500
  * call-seq:
@@ -5142,6 +5161,9 @@ rb_path_check(const char *path)
5142 5161
 }
5143 5162
 
5144 5163
 #ifndef _WIN32
  5164
+#ifdef __native_client__
  5165
+__attribute__((noinline))
  5166
+#endif
5145 5167
 int
5146 5168
 rb_file_load_ok(const char *path)
5147 5169
 {
6  gc.c
@@ -33,6 +33,12 @@
33 33
 #ifdef HAVE_SYS_RESOURCE_H
34 34
 #include <sys/resource.h>
35 35
 #endif
  36
+#if defined(__native_client__) && defined(NACL_NEWLIB)
  37
+# include "nacl/resource.h"
  38
+# undef HAVE_POSIX_MEMALIGN
  39
+# undef HAVE_MEMALIGN
  40
+
  41
+#endif
36 42
 
37 43
 #if defined _WIN32 || defined __CYGWIN__
38 44
 #include <windows.h>
4  gc.h
@@ -2,9 +2,9 @@
2 2
 #ifndef RUBY_GC_H
3 3
 #define RUBY_GC_H 1
4 4
 
5  
-#if defined(__x86_64__) && defined(__GNUC__)
  5
+#if defined(__x86_64__) && defined(__GNUC__) && !defined(__native_client__)
6 6
 #define SET_MACHINE_STACK_END(p) __asm__("movq\t%%rsp, %0" : "=r" (*(p)))
7  
-#elif defined(__i386) && defined(__GNUC__)
  7
+#elif defined(__i386) && defined(__GNUC__) && !defined(__native_client__)
8 8
 #define SET_MACHINE_STACK_END(p) __asm__("movl\t%%esp, %0" : "=r" (*(p)))
9 9
 #else
10 10
 NOINLINE(void rb_gc_set_stack_end(VALUE **stack_end_p));
30  io.c
@@ -28,7 +28,9 @@
28 28
 #if defined HAVE_NET_SOCKET_H
29 29
 # include <net/socket.h>
30 30
 #elif defined HAVE_SYS_SOCKET_H
31  
-# include <sys/socket.h>
  31
+# ifndef __native_client__
  32
+#  include <sys/socket.h>
  33
+# endif
32 34
 #endif
33 35
 
34 36
 #if defined(__BOW__) || defined(__CYGWIN__) || defined(_WIN32) || defined(__EMX__) || defined(__BEOS__) || defined(__HAIKU__)
@@ -47,6 +49,9 @@
47 49
 #if defined(HAVE_SYS_IOCTL_H) && !defined(_WIN32)
48 50
 #include <sys/ioctl.h>
49 51
 #endif
  52
+#if defined(__native_client__) && defined(NACL_NEWLIB)
  53
+# include "nacl/ioctl.h"
  54
+#endif
50 55
 #if defined(HAVE_FCNTL_H) || defined(_WIN32)
51 56
 #include <fcntl.h>
52 57
 #elif defined(HAVE_SYS_FCNTL_H)
@@ -161,7 +166,7 @@ void
161 166
 rb_maygvl_fd_fix_cloexec(int fd)
162 167
 {
163 168
   /* MinGW don't have F_GETFD and FD_CLOEXEC.  [ruby-core:40281] */
164  
-#ifdef F_GETFD
  169
+#if defined(F_GETFD) && !defined(__native_client__)
165 170
     int flags, flags2, ret;
166 171
     flags = fcntl(fd, F_GETFD); /* should not fail except EBADF. */
167 172
     if (flags == -1) {
@@ -187,7 +192,6 @@ rb_fd_fix_cloexec(int fd)
187 192
     if (max_file_descriptor < fd) max_file_descriptor = fd;
188 193
 }
189 194
 
190  
-
191 195
 int
192 196
 rb_cloexec_open(const char *pathname, int flags, mode_t mode)
193 197
 {
@@ -1502,6 +1506,7 @@ rb_io_set_pos(VALUE io, VALUE offset)
1502 1506
 
1503 1507
 static void clear_readconv(rb_io_t *fptr);
1504 1508
 
  1509
+#if defined(HAVE_FSYNC) || !defined(_WIN32)
1505 1510
 /*
1506 1511
  *  call-seq:
1507 1512
  *     ios.rewind    -> 0
@@ -1540,6 +1545,7 @@ rb_io_rewind(VALUE io)
1540 1545
 
1541 1546
     return INT2FIX(0);
1542 1547
 }
  1548
+#endif
1543 1549
 
1544 1550
 static int
1545 1551
 io_fillbuf(rb_io_t *fptr)
@@ -1629,6 +1635,7 @@ rb_io_eof(VALUE io)
1629 1635
     return Qfalse;
1630 1636
 }
1631 1637
 
  1638
+#ifdef HAVE_FSYNC
1632 1639
 /*
1633 1640
  *  call-seq:
1634 1641
  *     ios.sync    -> true or false
@@ -1683,8 +1690,6 @@ rb_io_set_sync(VALUE io, VALUE sync)
1683 1690
     return sync;
1684 1691
 }
1685 1692
 
1686  
-#ifdef HAVE_FSYNC
1687  
-
1688 1693
 /*
1689 1694
  *  call-seq:
1690 1695
  *     ios.fsync   -> 0 or nil
@@ -1709,14 +1714,19 @@ rb_io_fsync(VALUE io)
1709 1714
 
1710 1715
     if (io_fflush(fptr) < 0)
1711 1716
         rb_sys_fail(0);
1712  
-#ifndef _WIN32	/* already called in io_fflush() */
  1717
+# ifndef _WIN32	/* already called in io_fflush() */
1713 1718
     if ((int)rb_thread_io_blocking_region(nogvl_fsync, fptr, fptr->fd) < 0)
1714 1719
 	rb_sys_fail_path(fptr->pathv);
1715  
-#endif
  1720
+# endif
1716 1721
     return INT2FIX(0);
1717 1722
 }
1718 1723
 #else
1719  
-#define rb_io_fsync rb_f_notimplement
  1724
+# define rb_io_fsync rb_f_notimplement
  1725
+# define rb_io_sync rb_f_notimplement
  1726
+static VALUE rb_io_set_sync(VALUE io, VALUE sync) {
  1727
+  rb_notimplement();
  1728
+  /* NEVER REACHED */ return Qundef;
  1729
+}
1720 1730
 #endif
1721 1731
 
1722 1732
 #ifdef HAVE_FDATASYNC
@@ -8200,10 +8210,10 @@ rb_f_select(int argc, VALUE *argv, VALUE obj)
8200 8210
 
8201 8211
 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
8202 8212
  typedef unsigned long ioctl_req_t;
8203  
- #define NUM2IOCTLREQ(num) NUM2ULONG(num)
  8213
+# define NUM2IOCTLREQ(num) NUM2ULONG(num)
8204 8214
 #else
8205 8215
  typedef int ioctl_req_t;
8206  
- #define NUM2IOCTLREQ(num) NUM2INT(num)
  8216
+# define NUM2IOCTLREQ(num) NUM2INT(num)
8207 8217
 #endif
8208 8218
 
8209 8219
 struct ioctl_arg {
1  iseq.c
@@ -1548,4 +1548,3 @@ Init_ISeq(void)
1548 1548
     rb_define_singleton_method(rb_cISeq, "disasm", iseq_s_disasm, 1);
1549 1549
     rb_define_singleton_method(rb_cISeq, "disassemble", iseq_s_disasm, 1);
1550 1550
 }
1551  
-
3  missing/flock.c
... ...
@@ -1,7 +1,8 @@
1 1
 #include "ruby/config.h"
  2
+#include "ruby/ruby.h"
2 3
 
3 4
 #if defined _WIN32
4  
-#elif defined HAVE_FCNTL && defined HAVE_FCNTL_H
  5
+#elif defined HAVE_FCNTL && defined HAVE_FCNTL_H && !defined(__native_client__)
5 6
 
6 7
 /* These are the flock() constants.  Since this sytems doesn't have
7 8
    flock(), the values of the constants are probably not available.
60  nacl/GNUmakefile.in
... ...
@@ -0,0 +1,60 @@
  1
+# Copyright 2012 Google Inc. All Rights Reserved.
  2
+# Author: yugui@google.com (Yugui Sonoda)
  3
+
  4
+include Makefile
  5
+-include uncommon.mk
  6
+
  7
+NACL_SDK_ROOT=@NACL_SDK_ROOT@
  8
+NACL_TOOLCHAIN=@NACL_TOOLCHAIN@
  9
+NACL_TOOLCHAIN_DIR=$(NACL_SDK_ROOT)/toolchain/$(NACL_TOOLCHAIN)
  10
+PATH+=:$(NACL_TOOLCHAIN_DIR)/bin
  11
+PYTHON=@PYTHON@
  12
+
  13
+PPROGRAM=pepper-$(PROGRAM)
  14
+PEPPER_LIBS=-lppapi
  15
+PROGRAM_NMF=$(PROGRAM:.nexe=.nmf)
  16
+PPROGRAM_NMF=$(PPROGRAM:.nexe=.nmf)
  17
+
  18
+GNUmakefile: $(srcdir)/nacl/GNUmakefile.in
  19
+$(PPROGRAM): $(PROGRAM) pepper_main.$(OBJEXT)
  20
+	$(Q)$(MAKE) $(MFLAGS) PROGRAM=$(PPROGRAM) MAINOBJ="pepper_main.$(OBJEXT)" LIBS="$(LIBS) $(PEPPER_LIBS)" program
  21
+$(PROGRAM_NMF) $(PPROGRAM_NMF): $(@:.nmf=.nexe) nacl/create_nmf.rb
  22
+
  23
+.PHONY: pprogram package show_naclflags
  24
+.SUFFIXES: .nexe .nmf
  25
+.nexe.nmf:
  26
+	$(ECHO) generating manifest $@
  27
+	$(Q)$(MINIRUBY) $(srcdir)/nacl/create_nmf.rb --verbose=$(V) $(@:.nmf=.nexe) $@
  28
+
  29
+pepper_main.$(OBJEXT): $(srcdir)/nacl/pepper_main.c
  30
+	@$(ECHO) compiling nacl/pepper_main.c
  31
+	$(Q) $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(COUTFLAG)$@ -c $(srcdir)/nacl/pepper_main.c
  32
+ruby.$(OBJEXT):
  33
+	@$(ECHO) compiling $<
  34
+	$(Q) $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(COUTFLAG)$@.tmp -c $<
  35
+	$(Q) $(OBJCOPY) --weaken-symbol=rb_load_file $@.tmp $@
  36
+	@-$(RM) $@.tmp
  37
+file.$(OBJEXT):
  38
+	@$(ECHO) compiling $<
  39
+	$(Q) $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(COUTFLAG)$@.tmp -c $<
  40
+	$(Q) $(OBJCOPY) --weaken-symbol=rb_file_load_ok $@.tmp $@
  41
+	@-$(RM) $@.tmp
  42
+
  43
+all: pprogram
  44
+main: $(PROGRAM_NMF)
  45
+pprogram: showflags $(PPROGRAM) $(PPROGRAM_NMF)
  46
+program: $(PROGRAM_NMF)
  47
+prog: pprogram
  48
+
  49
+package: pprogram install-lib install-ext-comm install-ext-arch
  50
+	$(ECHO) generating manifest $@
  51
+	$(Q)$(MINIRUBY) $(srcdir)/nacl/package.rb $(prefix)
  52
+
  53
+showflags: show_naclflags
  54
+
  55
+show_naclflags:
  56
+	@echo "      PATH = $(PATH)"
  57
+	@echo "      NACL_SDK_ROOT = $(NACL_SDK_ROOT)"
  58
+
  59
+clean-local::
  60
+	-$(RM) $(PPROGRAM) pepper_main.$(OBJEXT) $(PROGRAM_NMF) $(PPRGORAM_NMF)
34  nacl/README.nacl
... ...
@@ -0,0 +1,34 @@
  1
+=begin
  2
+= Native Client port of Ruby
  3
+
  4
+= How to build
  5
+== Prerequisites
  6
+You need to install the following things before building NaCl port of Ruby.
  7
+* Ruby 1.9.3 or later
  8
+* Python 2.6 or later
  9
+* NativeClient SDK pepper 18 or later
  10
+* GNU make
  11
+
  12
+== Steps
  13
+(1) Extract all files from the tarball:
  14
+     $ tar xzf ruby-X.Y.Z.tar.gz
  15
+(2) Set NACL_SDK_ROOT environment vairanble to the path to the Native Client SDK you installed:
  16
+     $ export NACL_SDK_ROOT=/home/yugui/src/nacl_sdk/pepper_16
  17
+(3) Configure
  18
+     $ ./configure --prefix=/tmp/nacl-ruby --host=x86_64-nacl --with-baseruby=/path/to/ruby-1.9.3
  19
+(4) Make
  20
+     $ make
  21
+     $ make package
  22
+
  23
+Now you have ruby.nexe. You can run it by sel_ldr in NaCl SDK.
  24
+
  25
+"make package" installs "pepper-ruby.nexe", an example Pepper application that
  26
+embeds Ruby", and libraries to $prefix. You can run it by the following steps:
  27
+(5) Publish the $prefix directory on a web server
  28
+(6) Visit the example.html on the web server by a browser that implements Pepper 18 or later.
  29
+   -- e.g., Chrome 18 implements Pepper 18, Chrome 19 implements Pepper 19, ...
  30
+
  31
+= Copyright
  32
+* Copyright 2012 Google Inc. All Rights Reserved.
  33
+* Author: yugui@google.com (Yugui Sonoda)
  34
+=end
70  nacl/create_nmf.rb
... ...
@@ -0,0 +1,70 @@
  1
+#!/usr/bin/ruby
  2
+# Copyright:: Copyright 2012 Google Inc.
  3
+# License:: All Rights Reserved.
  4
+# Original Author:: Yugui Sonoda (mailto:yugui@google.com)
  5
+#
  6
+# Wrapper for create_nmf.py / generate_nmf.py
  7
+
  8
+require File.join(File.dirname(__FILE__), 'nacl-config')
  9
+
  10
+include NaClConfig
  11
+$verbosity = 0
  12
+
  13
+def usage_and_exit
  14
+  $stderr.puts "Usage: #{$PROGRAM_NAME} [--verbose=N] path/to/input.nexe path/to/output.nmf"
  15
+  exit false
  16
+end
  17
+
  18
+def create_dynamically_linked(nmf, exe)
  19
+  cmd = [
  20
+    PYTHON, CREATE_NMF,
  21
+    '-o', nmf,
  22
+    '-D', OBJDUMP,
  23
+    '-L', HOST_LIB,
  24
+    exe
  25
+  ]
  26
+  puts cmd.join(' ') if $verbosity > 0
  27
+  exec(*cmd)
  28
+end
  29
+
  30
+def create_statically_linked(nmf, exe)
  31
+  File.open(nmf, "w") {|f|
  32
+    f.write <<-EOS.gsub(/^ {6}/, '')
  33
+      {
  34
+        "program": {
  35
+          "#{ARCH}": {
  36
+            "url": "#{exe}"
  37
+          }
  38
+        }
  39
+      }
  40
+    EOS
  41
+  }
  42
+end
  43
+
  44
+def main
  45
+  while m = ARGV.first.match(/--([a-z-]+)(?:=(\S+))?/)
  46
+    case m[1]
  47
+    when 'verbose'
  48
+      usage_and_exit unless m[2][/\A[0-9]+\z/]
  49
+      $verbosity = m[2].to_i
  50
+    when 'help'
  51
+      usage_end_exit
  52
+    end
  53
+    ARGV.shift
  54
+  end
  55
+
  56
+  usage_and_exit if ARGV.size < 2
  57
+
  58
+  exe, nmf = ARGV[0], ARGV[1]
  59
+  if newlib?
  60
+    create_statically_linked(nmf, exe)
  61
+  else
  62
+    create_dynamically_linked(nmf, exe)
  63
+  end
  64
+end
  65
+
  66
+if __FILE__ == $0
  67
+   main()
  68
+end
  69
+
  70
+
15  nacl/dirent.h
... ...
@@ -0,0 +1,15 @@
  1
+/*
  2
+ * Copyright 2011 Google Inc. All Rights Reserved.
  3
+ * Author: yugui@google.com (Yugui Sonoda)
  4
+ */
  5
+#ifndef RUBY_NACL_DIRENT_H
  6
+#define RUBY_NACL_DIRENT_H
  7
+
  8
+/* NaCl SDK 0.3 has implementations of dir functions but no declaration in
  9
+ * dirent.h */
  10
+int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
  11
+void rewinddir(DIR *dirp);
  12
+long telldir(DIR *dirp);
  13
+void seekdir(DIR *dirp, long offset);
  14
+
  15
+#endif
150  nacl/example.html
... ...
@@ -0,0 +1,150 @@
  1
+<!DOCTYPE html>
  2
+<html>
  3
+<head>
  4
+  <title>Ruby Example</title>
  5
+
  6
+  <script type="text/javascript">
  7
+    RubyModule = null;  // Global application object.
  8
+    statusText = 'NO-STATUS';
  9
+    rubyReady = false;
  10
+
  11
+    // Indicate load success.
  12
+    function moduleDidLoad() {
  13
+      RubyModule = document.getElementById('ruby');
  14
+      form = document.getElementById('source-form');
  15
+      form.style.display = "block";
  16
+      updateStatus('SUCCESS');
  17
+    }
  18
+
  19
+    function evalSource() {
  20
+      if (rubyReady) {
  21
+        RubyModule.postMessage('eval:' + document.getElementById("source").value);
  22
+      } else {
  23
+        throw "Not yet ready";
  24
+      }
  25
+      return false;
  26
+    }
  27
+
  28
+    function RubyError(message) {
  29
+      this.message = message;
  30
+      this.toString = function() {
  31
+        return message;
  32
+      }
  33
+    }
  34
+
  35
+    function FatalError(message) {
  36
+      this.message = message;
  37
+    }
  38
+
  39
+    // The 'message' event handler.  This handler is fired when the NaCl module
  40
+    // posts a message to the browser by calling PPB_Messaging.PostMessage()
  41
+    // (in C) or pp::Instance.PostMessage() (in C++).  This implementation
  42
+    // simply displays the content of the message in an alert panel.
  43
+    function handleMessage(message_event) {
  44
+      var raw = message_event.data;
  45
+      var components;
  46
+      if (raw.indexOf("error") == 0) {
  47
+        components = raw.split(":", 2);
  48
+        throw new RubyError(components[1]);
  49
+      } else if (raw.indexOf("return") == 0) {
  50
+        components = raw.split(":", 2);
  51
+        document.getElementById("result").value = components[1];
  52
+      } else if (raw == "rubyReady") {
  53
+        rubyReady = true;
  54
+      } else {
  55
+        throw new FatalError(raw);
  56
+      }
  57
+    }
  58
+
  59
+    // If the page loads before the Native Client module loads, then set the
  60
+    // status message indicating that the module is still loading.  Otherwise,
  61
+    // do not change the status message.
  62
+    function pageDidLoad() {
  63
+      if (RubyModule == null) {
  64
+        updateStatus('LOADING...');
  65
+      } else {
  66
+        // It's possible that the Native Client module onload event fired
  67
+        // before the page's onload event.  In this case, the status message
  68
+        // will reflect 'SUCCESS', but won't be displayed.  This call will
  69
+        // display the current message.
  70
+        updateStatus();
  71
+      }
  72
+    }
  73
+
  74
+    // Set the global status message.  If the element with id 'statusField'
  75
+    // exists, then set its HTML to the status message as well.
  76
+    // opt_message The message test.  If this is null or undefined, then
  77
+    // attempt to set the element with id 'statusField' to the value of
  78
+    // |statusText|.
  79
+    function updateStatus(opt_message) {
  80
+      if (opt_message)
  81
+        statusText = opt_message;
  82
+      var statusField = document.getElementById('status_field');
  83
+      if (statusField) {
  84
+        statusField.innerHTML = statusText;
  85
+      }
  86
+    }
  87
+  </script>
  88
+</head>
  89
+<body onload="pageDidLoad()">
  90
+
  91
+<h1>Native Client Module Ruby</h1>
  92
+<p>
  93
+  <!-- Load the published .nexe.  This includes the 'nacl' attribute which
  94
+  shows how to load multi-architecture modules.  Each entry in the "nexes"
  95
+  object in the .nmf manifest file is a key-value pair: the key is the
  96
+  instruction set architecture ('x86-32', 'x86-64', etc.); the value is a URL
  97
+  for the desired NaCl module.
  98
+  To load the debug versions of your .nexes, set the 'nacl' attribute to the
  99
+  _dbg.nmf version of the manifest file.
  100
+
  101
+  Note: Since this NaCl module does not use any real-estate in the browser,
  102
+  it's width and height are set to 0.
  103
+
  104
+  Note: The <EMBED> element is wrapped inside a <DIV>, which has both a 'load'
  105
+  and a 'message' event listener attached.  This wrapping method is used
  106
+  instead of attaching the event listeners directly to the <EMBED> element to
  107
+  ensure that the listeners are active before the NaCl module 'load' event
  108
+  fires.  This also allows you to use PPB_Messaging.PostMessage() (in C) or
  109
+  pp::Instance.PostMessage() (in C++) from within the initialization code in
  110
+  your NaCl module.
  111
+  -->
  112
+  <div id="listener">
  113
+    <script type="text/javascript">
  114
+      var listener = document.getElementById('listener');
  115
+      listener.addEventListener('load', moduleDidLoad, true);
  116
+      listener.addEventListener('message', handleMessage, true);
  117
+    </script>
  118
+
  119
+    <embed name="nacl_module"
  120
+       id="ruby"
  121
+       width="0" height="0"
  122
+       src="ruby.nmf"
  123
+       type="application/x-nacl" />
  124
+    <form id="source-form" action="#" method="post" style="display:none"
  125
+      onsubmit="evalSource(); return false">
  126
+      <table>
  127
+        <tbody>
  128
+          <tr>
  129
+            <th>Source</th>
  130
+            <td>
  131
+              <textarea rows="10" cols="80" id="source"></textarea>
  132
+              <input type="submit" />
  133
+            </td>
  134
+          </tr>
  135
+          <tr>
  136
+            <th>Result</th>
  137
+            <td>
  138
+              <textarea rows="10" cols="80" id="result"></textarea>
  139
+            </td>
  140
+          </tr>
  141
+        </tbody>
  142
+      </table>
  143
+    </form>
  144
+  </div>
  145
+</p>
  146
+
  147
+<h2>Status</h2>
  148
+<div id="status_field">NO-STATUS</div>
  149
+</body>
  150
+</html>
7  nacl/ioctl.h
... ...
@@ -0,0 +1,7 @@
  1
+// Copyright 2012 Google Inc. All Rights Reserved.
  2
+// Author: yugui@google.com (Yugui Sonoda)
  3
+#ifndef RUBY_NACL_IOCTL_H
  4
+#define RUBY_NACL_IOCTL_H
  5
+int ioctl(int fd, int request, ...);
  6
+struct flock{};
  7
+#endif
61  nacl/nacl-config.rb
... ...
@@ -0,0 +1,61 @@
  1
+#!/usr/bin/ruby
  2
+#
  3
+# Copyright:: Copyright 2012 Google Inc.
  4
+# License:: All Rights Reserved.
  5
+# Original Author:: Yugui Sonoda (mailto:yugui@google.com)
  6
+#
  7
+# Convenient functions/constants for native client specific configurations.
  8
+require 'rbconfig'
  9
+
  10
+module NaClConfig
  11
+  config = RbConfig::CONFIG
  12
+
  13
+  cpu_nick = config['host_alias'].sub(/-gnu$|-newlib$/, '').sub(/-nacl$/, '')
  14
+  ARCH = cpu_nick.sub('x86_64', 'x86-64').sub(/i.86/, 'x86-32')
  15
+  HOST = ARCH.sub(/x86-../, 'x86_64') + '-nacl'
  16
+
  17
+  lib_suffix = config['host_cpu'][/i.86/] ? '32' : ''
  18
+  PYTHON = config['PYTHON']
  19
+  OBJDUMP = config['OBJDUMP']
  20
+  SDK_ROOT = config['NACL_SDK_ROOT']
  21
+  CREATE_NMF = [
  22
+    File.join(SDK_ROOT, 'build_tools', 'nacl_sdk_scons', 'site_tools', 'create_nmf.py'),
  23
+    File.join(SDK_ROOT, 'tools', 'create_nmf.py')
  24
+  ].find{|path| File.exist?(path) }
  25
+  HOST_LIB = File.join(SDK_ROOT, 'toolchain', config['NACL_TOOLCHAIN'], HOST, "lib#{lib_suffix}")
  26
+
  27
+  INSTALL_PROGRAM = config['INSTALL_PROGRAM']
  28
+  INSTALL_LIBRARY = config['INSTALL_DATA']
  29
+
  30
+  SEL_LDR = [
  31
+    File.join(SDK_ROOT, 'toolchain', config['NACL_TOOLCHAIN'], 'bin', "sel_ldr_#{cpu_nick}"),
  32
+    File.join(SDK_ROOT, 'tools', "sel_ldr_#{cpu_nick}")
  33
+  ].find{|path| File.executable?(path)}
  34
+  IRT_CORE = [
  35
+    File.join(SDK_ROOT, 'toolchain', config['NACL_TOOLCHAIN'], 'bin', "irt_core_#{cpu_nick}.nexe"),
  36
+    File.join(SDK_ROOT, 'tools', "irt_core_#{cpu_nick}.nexe")
  37
+  ].find{|path| File.executable?(path)}
  38
+  RUNNABLE_LD = File.join(HOST_LIB, 'runnable-ld.so')
  39
+
  40
+  module_function
  41
+
  42
+  def newlib?
  43
+    RbConfig::CONFIG['NACL_SDK_VARIANT'] == 'newlib'
  44
+  end
  45
+
  46
+  def self.config(name)
  47
+    if NaClConfig::const_defined?(name.upcase)
  48
+      NaClConfig::const_get(name.upcase)
  49
+    elsif NaClConfig::respond_to?(name) and NaClConfig::method(name).arity == 0
  50
+      NaClConfig::send(name)
  51
+    else
  52
+      raise ArgumentError, "No such config: #{name}"
  53
+    end
  54
+  end
  55
+end
  56
+
  57
+if $0 == __FILE__
  58
+  ARGV.each do |arg|
  59
+    puts NaClConfig::config(arg)
  60
+  end
  61
+end
109  nacl/package.rb
... ...
@@ -0,0 +1,109 @@
  1
+#!/usr/bin/ruby
  2
+# Copyright:: Copyright 2012 Google Inc.
  3
+# License:: All Rights Reserved.
  4
+# Original Author:: Yugui Sonoda (mailto:yugui@google.com)
  5
+#
  6
+# Generates a runnable package of the pepper API example.
  7
+
  8
+require File.join(File.dirname(__FILE__), 'nacl-config')
  9
+require 'json'
  10
+require 'find'
  11
+require 'fileutils'
  12
+
  13
+include NaClConfig
  14
+
  15
+class Installation
  16
+  include NaClConfig
  17
+
  18
+  SRC_DIRS = [ Dir.pwd, HOST_LIB ]
  19
+
  20
+  def initialize(destdir)
  21
+    @destdir = destdir
  22
+    @manifest = {
  23
+      "files" => {}
  24
+    }
  25
+    ruby_libs.each do |path|
  26
+      raise "Collision of #{path}" if @manifest['files'].key? path
  27
+      @manifest['files'][path] = {
  28
+        ARCH => {
  29
+          "url" => path
  30
+        }
  31
+      }
  32
+      if path[/\.so$/]
  33
+        alternate_path = path.gsub('/', "_")
  34
+        raise "Collision of #{alternate_path}" if @manifest['files'].key? alternate_path
  35
+        @manifest['files'][alternate_path] = {
  36
+          ARCH => {
  37
+            "url" => path
  38
+          }
  39
+        }
  40
+      end
  41
+    end
  42
+  end
  43
+
  44
+  def manifest
  45
+    @manifest.dup
  46
+  end
  47
+
  48
+  def install_program(basename)
  49
+    do_install_binary(basename, File.join(@destdir, "bin", ARCH))
  50
+    @manifest["program"] = {
  51
+      ARCH => {
  52
+        "url" => File.join("bin", ARCH, basename)
  53
+      }
  54
+    }
  55
+  end
  56
+
  57
+  def install_library(name, basename)
  58
+    do_install_binary(basename, File.join(@destdir, "lib", ARCH))
  59
+    @manifest["files"][name] = {
  60
+      ARCH => {
  61
+        "url" => File.join("lib", ARCH, basename)
  62
+      }
  63
+    }
  64
+  end
  65
+
  66
+  private
  67
+  def do_install_binary(basename, dest_dir)
  68
+    full_path = nil
  69
+    catch(:found) {
  70
+      SRC_DIRS.each do |path|
  71
+        full_path = File.join(path, basename)
  72
+        if File.exist? full_path
  73
+          throw :found
  74
+        end
  75
+      end
  76
+      raise Errno::ENOENT, "No such file to install: %s" % basename
  77
+    }
  78
+    FileUtils.mkdir_p dest_dir
  79
+    system("#{INSTALL_PROGRAM} #{full_path} #{dest_dir}")
  80
+  end
  81
+
  82
+  def ruby_libs
  83
+    Find.find(RbConfig::CONFIG['rubylibdir']).select{|path| File.file?(path) }.map{|path| path.sub("#{@destdir}/", "") }
  84
+  end
  85
+end
  86
+
  87
+def install(destdir)
  88
+  inst = Installation.new(destdir)
  89
+  manifest = JSON.parse(File.read("pepper-ruby.nmf"))
  90
+
  91
+  program = File.basename(manifest['program'][ARCH]['url'])
  92
+  inst.install_program(program)
  93
+
  94
+  manifest['files'].each do |name, attr|
  95
+    inst.install_library(name, File.basename(attr[ARCH]["url"]))
  96
+  end
  97
+
  98
+  File.open(File.join(destdir, "ruby.nmf"), "w") {|f|
  99
+    f.puts JSON.pretty_generate(inst.manifest)
  100
+  }
  101
+end
  102
+
  103
+def main
  104
+  install(ARGV[0])
  105
+end
  106
+
  107
+if __FILE__ == $0
  108
+  main()
  109
+end
924  nacl/pepper_main.c
... ...
@@ -0,0 +1,924 @@
  1
+/******************************************************************************
  2
+ Copyright 2012 Google Inc. All Rights Reserved.
  3
+ Author: yugui@google.com (Yugui Sonoda)
  4
+ ******************************************************************************/
  5
+
  6
+#include <stdlib.h>
  7
+#include <stdio.h>
  8
+#include <string.h>
  9
+#include <pthread.h>
  10
+#include <sys/stat.h>
  11
+#include <fcntl.h>
  12
+#include <pthread.h>
  13
+#include "ppapi/c/pp_errors.h"
  14
+#include "ppapi/c/pp_module.h"
  15
+#include "ppapi/c/pp_var.h"
  16
+#include "ppapi/c/ppb.h"
  17
+#include "ppapi/c/ppb_core.h"
  18
+#include "ppapi/c/ppb_file_ref.h"
  19
+#include "ppapi/c/ppb_instance.h"