What-ho, chums! I have spent too much time musing about Android compatibility layers since I posted the following over a fortnight ago:
As you may surmise, I know very little about Android and, unfortunately, I failed to spark a discussion with that post. I try again now.
I know very little about Microsoft Windows internals as well, so my assumption that WINE does system call redirection may be wrong; I have learned, since, that direct/naked syscall use on Windows is highly discouraged, as syscalls and syscall ID numbers can (and do) change from release to release (and from hotfix to hotfix -- there is absolutely no stable kernel ABI, unlike with Linux). Instead, Windows application programmers are expected to use the Windows API, which, I suppose, fills the same niche as glibc; the Windows API itself is over the Native API, which is not supposed to be used outside Microsoft. WINE re-implements these APIs (ABIs?), so I suppose any syscall redirection (if it exists) is of minor importance for WINE. It does use the ptrace syscall (see below), though, for what, I know not.
My reading suggests that the only way to intercept syscalls is with the kernel's help, using the ptrace syscall. So a compatibility layer might try to use ptrace to intercept all syscalls from Android/Dalvik, resending those that "exist" in the mainline Linux kernel while diverting syscalls with ID numbers that do not "exist" (such as any involved with Binder) to the compatibility layer's own code. While researching this, I came across User Mode Linux, which seems to do something very similar: it is a copy of the Linux Kernel as a normal ELF executable that runs on top of the host Linux system, with all programs launched by this guest kernel having their syscalls intercepted with ptrace and forwarded when appropriate. It seems to be intended for testing development versions of the Linux kernel on top of a stable system -- and the Android kernel can be considered to be simply a development kernel with extra features. Three problems exist that I can think of: first, User Mode Linux lacks an ARM version so far (there exist x86 -- not sure about x86_64 -- and PowerPC versions) so that would have to be created; second, User Mode Linux does not seem to be a hugely active project at the moment (I could be wrong); third, User Mode Linux may be nearer to virtualization than WINE, so it may be too "heavy" -- that is, why not just use a full virtual machine with, presumably, less effort? Not to mention that it may be that Android programs very rarely use Linux syscalls directly (does Dalvik's dynamic recompiler, or Android's newer AOT compiler, generate syscall instructions?), like with Windows (after all, if the Android kernel's features were mainlined, would the new syscalls keep their current ID numbers? Also, I am not sure that the Android developers have the same attitude to binary code compatibility that Linus Torvalds professes to have regarding to the Linux ABI and its syscalls).
Aside from the kernel, there are Dalvik/ART(Android Runtime), Bionic libc and the windowing system (SurfaceFlinger?). I mentioned libhybris in my quoted post, though if using User Mode Linux I suppose it may make more sense to use Bionic directly, with Dalvik/ART on top of that. If not using User Mode Linux, libhybris may be used for Dalvik/ART. For the windowing system, there would need to be either a Xephyr equivalent or direct use of a Linux framebuffer (or virtual console, whatever it is called, it is switched with CTRL+ALT+F(X) where X is from 1 to 7 or 8, usually -- by the way I have not been able to do this on a Pandora, any idea why?). I assume that the latter would be simpler.
Any comments? Do I grossly misunderstand any of this? Can kernel differences be ignored due to ABI instability leading to Android programs not using syscalls directly? How does using User Mode Linux compare with using a more general purpose virtualization program?
[doublepost=1451524979,1451505788][/doublepost]Oh, incidentally, would there be any substantial downside to using the Android kernel by default in Pyra OS? As far as I know, the Android kernel includes only additions compared with the mainline kernel it is based on, so there would be extra work (how much, I know not) importing features to/from the latest mainline kernel. However, unless I misunderstand something, it would allow the use of a chroot plus some way of choosing to use Bionic within the chroot (is that not automatic?) plus Dalvik/ART plus SurfaceFlinger (or whatever it is) on a separate framebuffer/virtual console with relatively little work.
A compatibility layer for Android may provide better performance, though. It should be easier to do than WINE (hey, does anyone know of an explanation of how WINE works, at a low level? I am particularly interested in how it does system call or library call redirection), as there are some open source components that (seem to) already exist: the Hybris library (https://en.wikipedia.org/wiki/Hybris_(software)) that is a compatibility layer just for the Bionic C library on GLIBC; plus the FOSS components of Android itself. Given that Android uses a variant of the Linux kernel, the wineserver equivalent (I think that is the part involved with system call redirection) would only need to cover the Android kernel's additions, like Binder, with other syscalls getting passed along, unchanged (someone please correct any misconceptions).
As you may surmise, I know very little about Android and, unfortunately, I failed to spark a discussion with that post. I try again now.
I know very little about Microsoft Windows internals as well, so my assumption that WINE does system call redirection may be wrong; I have learned, since, that direct/naked syscall use on Windows is highly discouraged, as syscalls and syscall ID numbers can (and do) change from release to release (and from hotfix to hotfix -- there is absolutely no stable kernel ABI, unlike with Linux). Instead, Windows application programmers are expected to use the Windows API, which, I suppose, fills the same niche as glibc; the Windows API itself is over the Native API, which is not supposed to be used outside Microsoft. WINE re-implements these APIs (ABIs?), so I suppose any syscall redirection (if it exists) is of minor importance for WINE. It does use the ptrace syscall (see below), though, for what, I know not.
My reading suggests that the only way to intercept syscalls is with the kernel's help, using the ptrace syscall. So a compatibility layer might try to use ptrace to intercept all syscalls from Android/Dalvik, resending those that "exist" in the mainline Linux kernel while diverting syscalls with ID numbers that do not "exist" (such as any involved with Binder) to the compatibility layer's own code. While researching this, I came across User Mode Linux, which seems to do something very similar: it is a copy of the Linux Kernel as a normal ELF executable that runs on top of the host Linux system, with all programs launched by this guest kernel having their syscalls intercepted with ptrace and forwarded when appropriate. It seems to be intended for testing development versions of the Linux kernel on top of a stable system -- and the Android kernel can be considered to be simply a development kernel with extra features. Three problems exist that I can think of: first, User Mode Linux lacks an ARM version so far (there exist x86 -- not sure about x86_64 -- and PowerPC versions) so that would have to be created; second, User Mode Linux does not seem to be a hugely active project at the moment (I could be wrong); third, User Mode Linux may be nearer to virtualization than WINE, so it may be too "heavy" -- that is, why not just use a full virtual machine with, presumably, less effort? Not to mention that it may be that Android programs very rarely use Linux syscalls directly (does Dalvik's dynamic recompiler, or Android's newer AOT compiler, generate syscall instructions?), like with Windows (after all, if the Android kernel's features were mainlined, would the new syscalls keep their current ID numbers? Also, I am not sure that the Android developers have the same attitude to binary code compatibility that Linus Torvalds professes to have regarding to the Linux ABI and its syscalls).
Aside from the kernel, there are Dalvik/ART(Android Runtime), Bionic libc and the windowing system (SurfaceFlinger?). I mentioned libhybris in my quoted post, though if using User Mode Linux I suppose it may make more sense to use Bionic directly, with Dalvik/ART on top of that. If not using User Mode Linux, libhybris may be used for Dalvik/ART. For the windowing system, there would need to be either a Xephyr equivalent or direct use of a Linux framebuffer (or virtual console, whatever it is called, it is switched with CTRL+ALT+F(X) where X is from 1 to 7 or 8, usually -- by the way I have not been able to do this on a Pandora, any idea why?). I assume that the latter would be simpler.
Any comments? Do I grossly misunderstand any of this? Can kernel differences be ignored due to ABI instability leading to Android programs not using syscalls directly? How does using User Mode Linux compare with using a more general purpose virtualization program?
[doublepost=1451524979,1451505788][/doublepost]Oh, incidentally, would there be any substantial downside to using the Android kernel by default in Pyra OS? As far as I know, the Android kernel includes only additions compared with the mainline kernel it is based on, so there would be extra work (how much, I know not) importing features to/from the latest mainline kernel. However, unless I misunderstand something, it would allow the use of a chroot plus some way of choosing to use Bionic within the chroot (is that not automatic?) plus Dalvik/ART plus SurfaceFlinger (or whatever it is) on a separate framebuffer/virtual console with relatively little work.