Octocontrabass wrote:
It's already pretty common for userland shared libraries to share their read-only pages between users, so what you're describing is extending this mechanism to include the kernel. If your target is a system with extremely limited memory, it may be worth the extra effort, but otherwise there's not much to gain.
It also opens your kernel up to cache side-channel attacks, if you're worried about that sort of thing. (Of course, cache side-channel attacks are also possible between users that share pages.)
If I am implementing this, how should I structure the targets? Something like this:
- Build the cross-shared klibc first as a PIC dynamic library,
- Build the kernel targeting high half loading and linked against that dynamic klibc,
- Build a statically linked kernel dynamic linker (kdyld,)
- Build an early boot stub that prepares and satisfies some basic assumptions and provides basic functionalities for the dynamic linker, for example paging.
- Build the kernel image by packing the early boot stub, kernel dynamic linker, the kernel itself and klibc in one binary.
Upon boot,
- the early boot stub starts paging and calls the dynamic linker with information about the packed-in kernel and klibc
- The kdyld puts klibc and kernel proper into the correct places and edit the pointers appropriately using the paging facility of early boot stub. This serves as the replacement of a higher half kernel's relocation porcess.
- The kernel starts, reads the data left behind from boot stub and kdyld to prepare its own paging and module loading facility, and frees the memory used by the boot stub and kdyld.