imcplugin
In order to support running dynamically-linked glibc code under NaCl from the web browser, and to better understand the browser-plugin interface, I have created a minimal NaCl NPAPI plugin. Unlike the existing NaCl plugin, it supports calling Javascript asynchronously from the NaCl process.
Background: glibc's dynamic linker expects to be able to use open() to open library .so files. This works with sel_ldr's -d (debug) option, where NaCl's open() syscall accesses the local filesystem. In the NaCl browser plugin, this syscall is of course not available. This is not itself a problem, because open() in glibc can be reimplemented as a remote procedure call across a NaCl IMC socket, using NaCl's imc_sendmsg() and imc_recvmsg() syscalls. The idea is that Javascript code would handle an open() request by firing off an AJAX request for the file, and, on completion of the fetch, by sending the file descriptor to the NaCl process in a reply message. This is similar to how open() is implemented in Plash. Although NaCl's existing browser plugin backends already support sending file descriptors to the NaCl process, they don't support calling Javascript asynchronously from the NaCl process.
Features
It can receive messages asynchronously from the NaCl process and call a Javascript callback function in the browser. (This uses NPN_PluginThreadAsyncCall() which is relatively new.)
- It does not attempt to perform marshalling of Javascript objects such as numbers, bools and arrays. Messages consist only of a string and an array of FDs. Marshalling can instead be done outside the plugin in untrusted Javascript.
Non-blocking: It will not block waiting for messages from the NaCl process. (However, sending to a socket with a full buffer may block.)
The interface allows spawning multiple NaCl processes. Launching processes is done via a scripted interface; the plugin does not look at the <object> element's "src" attribute.
- Unlike the SRPC plugin, neither the parent nor the child need to do connect() or accept() on startup. The connection is in a ready-to-go state.
The plugin allows passing command line arguments to the NaCl process. (However, for economy of mechanism it might be better to pass these arguments across the socket.)
- It has some automated tests.
- It is written in C.
It is smaller: while npapi_plugin/srpc contains ~6800 lines of code, imcplugin.c is <1000 lines. (Of course, adding features such as framebuffer support would reduce tha gap.)
However:
- It does not provide a framebuffer video interface.
- Reporting errors back to Javascript is not complete.
- sel_ldr processes are not yet shut down when the plugin is shut down.
- It does not yet implement a same-origin check.
- It is not hooked into the scons build system.
The code is part of my NaCl branch, in http://repo.or.cz/w/nativeclient.git.
