ish README

The project's README from github.com/ish-app/ish. As one markdown file: README.md.

iSH

Build Status goto counter fuck counter shit counter

A project to get a Linux shell running on iOS, using usermode x86 emulation and syscall translation.

For the current status of the project, check the issues tab, and the commit logs.

Hacking

This project has a git submodule, make sure to clone with --recurse-submodules or run git submodule update --init after cloning.

You'll need these things to build the project:

Build for iOS

Open the project in Xcode, open iSH.xcconfig, and change ROOT_BUNDLE_IDENTIFIER to something unique. You'll also need to update the development team ID in the project (not target!) build settings. Then click Run. There are scripts that should do everything else automatically. If you run into any problems, open an issue and I'll try to help.

Build command line tool for testing

To set up your environment, cd to the project and run meson build to create a build directory in build. Then cd to the build directory and run ninja.

To set up a self-contained Alpine linux filesystem, download the Alpine minirootfs tarball for i386 from the Alpine website and run ./tools/fakefsify, with the minirootfs tarball as the first argument and the name of the output directory as the second argument. Then you can run things inside the Alpine filesystem with ./ish -f alpine /bin/sh, assuming the output directory is called alpine. If tools/fakefsify doesn't exist for you in your build directory, that might be because it couldn't find libarchive on your system (see above for ways to install it.)

You can replace ish with tools/ptraceomatic to run the program in a real process and single step and compare the registers at each step. I use it for debugging. Requires 64-bit Linux 4.11 or later.

Logging

iSH has several logging channels which can be enabled at build time. By default, all of them are disabled. To enable them:

Available channels:

A note on the interpreter

Possibly the most interesting thing I wrote as part of iSH is the interpreter. It's not quite a JIT since it doesn't target machine code. Instead it generates an array of pointers to functions called gadgets, and each gadget ends with a tailcall to the next function; like the threaded code technique used by some Forth interpreters. The result is a speedup of roughly 3-5x compared to emulation using a simpler switch dispatch.

Unfortunately, I made the decision to write nearly all of the gadgets in assembly language. This was probably a good decision with regards to performance (though I'll never know for sure), but a horrible decision with regards to readability, maintainability, and my sanity. The amount of bullshit I've had to put up with from the compiler/assembler/linker is insane. It's like there's a demon in there that makes sure my code is sufficiently deformed, and if not, makes up stupid reasons why it shouldn't compile. In order to stay sane while writing this code, I've had to ignore best practices in code structure and naming. You'll find macros and variables with such descriptive names as ss and s and a. Assembler macros nested beyond belief. And to top it off, there are almost no comments.

So a warning: Long-term exposure to this code may cause loss of sanity, nightmares about GAS macros and linker errors, or any number of other debilitating side effects. This code is known to the State of California to cause cancer, birth defects, and reproductive harm.

ish (ish-app/ish)

Searching Database…

20.6K ·GitHub
What is this?iSH is an open-source iOS app that gives you a Linux shell on your iPhone or iPad. It emulates an x86 processor in usermode and translates Linux syscalls, so Linux command-line programs run on iOS as they are.
Is this an app I install on my iPhone, or something I run on a computer?It's a regular iOS app: the README links to its App Store page and a TestFlight beta, so no jailbreak is needed. There is also a separate command-line version that developers build and run on macOS or Linux for testing.
What do I need to have installed to build it?Python 3 with Meson, Ninja, Clang and LLD, sqlite3 and libarchive — on a Mac that's brew install llvm plus brew install libarchive, with Xcode for the iOS build itself.
Is it a real, full Linux system running on my phone?It's usermode only: iSH emulates the x86 instruction set and translates syscalls, so you get a Linux userspace environment rather than a booted Linux kernel. For what currently works, the README points to the issues tab and commit logs.
Would a non-developer get anything out of this, or is it strictly for terminal people?It's mainly for developers and Unix fans who want a portable Linux command line, but the project links a wiki with help and tutorials, so a curious beginner can find their way around it too.
Does it work on iPads too, or just iPhones?iSH is an iOS app, so it runs on iPhone and iPad via the App Store or TestFlight. The only other way to run it is the command-line testing build, which compiles on macOS or Linux.
How does the emulation actually work under the hood?There's no JIT. iSH generates an array of pointers to functions called gadgets, and each gadget ends with a tailcall to the next one — the same threaded-code technique some Forth interpreters use. Nearly all of those gadgets are hand-written assembly.
Can I run iSH on a Mac or Linux machine for testing?Yes. Run meson build, then ninja inside the build directory, turn an Alpine minirootfs tarball into a filesystem with tools/fakefsify, and start it with ./ish -f alpine /bin/sh. For debugging there's tools/ptraceomatic, which single-steps the program in a real process and compares registers — it requires 64-bit Linux 4.11 or later.
Which Linux distro does it actually run?It's built around Alpine Linux: you download the Alpine minirootfs tarball for i386 and convert it into a self-contained filesystem directory with tools/fakefsify, and that's the filesystem the shell runs inside.
Is the source code pleasant to work with?The author himself warns you off: cryptic names like ss, s and a, assembler macros nested beyond belief, and almost no comments. The README literally says long-term exposure to this code may cause loss of sanity and nightmares about GAS macros and linker errors.
Creator
ish-app
Size
5.5 MB
Stars
20.6K
Age
9y
Commits · 90 Days