Skip to content
Search

LinuxPDF

lastmod 2025-11-04created 2025-02-051 edits

Running Linux with a RISC-V emulator inside a PDF

Features

  • PDF files are easy to think of as static documents, but they actually include support for Javascript
    • The PDF standard has its own Javascript standard library
    • Modern browsers such as Chromium and Firefox implement only an extremely limited API for security reasons
  • Only Adobe Acrobat supported the full spec of Javascript in PDF, which includes a very broad range of features such as 3D rendering, HTTP requests, and detecting all of the user's monitors
  • Even with the limited browser API, any computational logic can be performed, but IO is very limited
  • C code can be compiled to asm.js and run inside a PDF
    • Uses an old version of Emscripten (e.g. 1.39.20, which supports the asm.js target)
    • The structure: the TinyEMU RISC-V emulator is modified, compiled to asm.js, and run from the PDF
  • Screen output and input work the same way as in DoomPDF (running Doom inside a PDF)
    • The screen uses one text field per line and represents pixel states with ASCII characters
    • Input passes keystrokes to the VM through a virtual keyboard and a text box
  • Significant performance problems
    • E.g. booting the Linux kernel takes about 30-60 seconds, more than 100 times slower than running it normally
    • V8 in Chrome's PDF engine has JIT disabled, which greatly degrades performance
  • The root file system can be either 64-bit or 32-bit
    • The default is a 32-bit Buildroot system (taken from the original TinyEMU examples)
    • There is also a 64-bit Alpine Linux version, but it is about 2x slower, so it is usually not used

See also

Favorite site

author Zer0 sitemap