Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run compiled files on Google Native Client

How to run compiled files directly using Google Native Client (PNaCl)? It tried checking their documentation. It said that -

Native Client is a sandbox for running compiled C and C++ code in the browser efficiently and securely, independent of the user’s operating system.

But in their documentation, they only deal with sources of the application. Is there any way to run compiled code directly? I want to run files with .exe and .deb extensions


I'm not limiting the answer to Native Client. Any mechanism which can do that sort of work will work for me.

like image 304
Arulx Z Avatar asked Aug 29 '15 10:08

Arulx Z


1 Answers

You can't run pre-compiled code within NaCl or PNaCl. You have to use the compilers provided by the SDK. There are three main reasons for this:

  • NaCl is an execution sandbox which relies on crafting machine code (x86-32, x86-64, ARM, MIPS) in a very particular way. This is regular machine code from the CPU's point of view, but allows the sandbox to run a validator and make sure that the code can't do anything malicious. This is called Software Fault Isolation, and is explained in this paper. The other ISA sandboxes are also documented.
  • PNaCl targets NaCl, but is an architecture-agnostic intermediate representation. This means that you ship what can be thought of as bytecode, and the browser figures out which type of machine code (x86-32, x86-64, ARM, MIPS) to generate based on the user's machine. The developer doesn't generate 4 binaries.
  • In both above cases, the code can execute as-is on Windows, MacOSX, Linux, ChromeOS, and (while not usually shipping) Android. This means that the NaCl sandbox presents itself as an operating system, and offers the same APIs. These APIs are different from other OSes, though they're pretty close to POSIX especially if you use nacl_io.

The above points require that you use the compilers provided by the SDK.

It is technically possible to run binaries built for other architectures or operating systems since the system is Turing-complete. That's what QEMU does, what Rosetta did, what Transmeta did, and what the Android Runtime for Chome (ARC) enables. This usually requires binary translation and emulation of all operating system calls. This is technically difficult to implement, and often has severe performance cost. I do not recommend exploring this option.

like image 80
JF Bastien Avatar answered Oct 12 '22 14:10

JF Bastien