3

I'm looking for a reliable, unobtrusive runtime check a process can make for whether it's running on Linux without mmu. By unobtrusive, I mean having minimal or no side effects on process state. For example, getting EINVAL from fork would be one indication, but would create a child process if the test failed. Attempting to cause a fault and catch a signal is out of the question since it involves changing global signal dispositions. Anything involving /proc or /sys would be unreliable since they may not be mounted/visible (e.g. in chroot or mount namespace).

Failure of mprotect with ENOSYS seems to be reliable, and can be done without any side effects beyond the need to map a test page to attempt it on. But I'm not sure if it's safe to rely on this.

Are there any better/recommended ways to go about this?

Before anyone tries to challenge the premise and answer that this is known statically at compile time, no, it's not. Assuming you build a position-independent executable for an ISA level supported by both mmu-ful and mmu-less variants of the architecture, it can run on either. (I'm the author of the kernel commit that made this work.)

R.. GitHub STOP HELPING ICE
  • 195,354
  • 31
  • 331
  • 669
  • Why not test the functions you need to use at run-time to ensure the process can do what it needs to do? It's conceivable you could have a system with a half-baked MMU that doesn't do what you need, but it technically has an MMU. – tadman Nov 24 '19 at 00:01
  • 3
    @tadman: The choices I'm trying to make are things like omitting guard pages when they're not going to be able to trap anything and going to waste physical memory, and avoiding preallocation of virtual memory when virtual=physical. So it's not really a matter of "test the thing you want to do". – R.. GitHub STOP HELPING ICE Nov 24 '19 at 00:04

0 Answers0