realksh(8)

πŸ’… realksh(8) β€” the manual page, but make it make sense

okay bestie, pull up a chair, we're talking about realksh πŸ¦‹


✨ NAME ✨

realksh.c β€” a shell for running Kernel-mode C code πŸ‘‘


✨ SYNOPSIS ✨

realksh.c

that's it. that's the whole synopsis. iconic behavior honestly 🌸


✨ DESCRIPTION ✨

so realksh.c is an interactive shell that runs C source code, no cap. every line you type gets treated as a line inside the module_init() function, and the C code that comes out of it gets compiled into a kernel module. then that module gets inserted into the kernel, and then removed from the kernel. that's the whole loop. it's giving compile-insert-remove, compile-insert-remove πŸ’«

and because debugging kernel stuff blind is a nightmare, any kernel message output that's prepended with KMSG: gets copied over to standard out for convenience β€” so functions like printk are right there for easy debugging. literally your little bestie for printf-style snooping πŸ™ˆ

now here's a cute little trick: if you enter a line starting with #, like #include <stdio.h>, that line gets added to every code after that at the start of sourcecode. so it sticks around for everything you write from then on. very "set it and forget it" energy ✨

you can see the whole list of those lines with ## πŸ‘€


✨ EXAMPLES ✨

here's an example session, look at her go πŸŽ€

$ sudo ./realksh.c
REAL ksh: printk ("hello\n");
  Building modules, stage 2.
KMSG: <4>hello

REAL ksh: printk ("%x\n", mfmsr());
  Building modules, stage 2.
KMSG: <4>9032

REAL ksh: printk ("%x\n", mfspr(SPRN_MMCR0));
  Building modules, stage 2.
KMSG: <4>0

REAL ksh:

the way it just prints your hex and moves on… main character energy, fr fr πŸ”₯


✨ INTERNALS ✨

okay so here's what the C code actually looks like under the hood 🫢

#include <linux/module.h>
#include <linux/init.h>
MODULE_AUTHOR("dancerj");
MODULE_DESCRIPTION("....");
MODULE_LICENSE("GPL");
static int __init realkshmod2_init(void)
{
input-line
return 0;
}
static void __exit realkshmod2_cleanup(void)
{
}
module_init(realkshmod2_init);
module_exit(realkshmod2_cleanup);

see how your input-line just slots right in there? you're basically writing a function body and the shell handles all the boilerplate for you. chef's kiss πŸ’…


✨ AUTHOR ✨

Junichi Uekawa (dancer@debian.org) β€” the legend themselves πŸ’–

the upstream page is available at http://www.netfort.gr.jp/~dancer/software/ β€” go say hi 🌈


✨ SEE ALSO ✨


and that's the whole vibe check bestie πŸ¦‹ this page came from binfmt_misc, written by Dancer, dated 2006 Jan 1, and it lives as realksh(8). stay slay, keep your modules GPL'd, and never forget to remove what you inserted πŸ˜­πŸ’–