Is it possible to write a Linux kernel mode debugger for Intel x86-64 in Common Lisp and with which Common Lisp implementation [s]?

I am interested in developing some kind of ring0 kernel mode debugger for x86-64 in Common Lisp that will be loaded as a Linux kernel module, and since I prefer Common Lisp C in general programming, I wonder how different implementations of Common Lisp would fit this task programming.

The debugger will use some external disassembling library, such as udis86 through some FFI . It seems to me that the easiest way to write kernel modules in C is because they must contain the C functions int init_module(void) and void cleanup_module(void) ( Linux kernel module programming guide ), so the kernel kernel module code will call Common Lisp code from C using CFFI . The idea was to create a ring0 debugger for 64-bit Linux, inspired by the idea of Rasta Ring 0 Debugger , which is only available for 32-bit Linux and requires a PS / 2 keyboard. I think the most difficult part will be the actual debugger code in terms of hardware and software, and the low-level processing of a video, keyboard, or USB input device. The built-in assembly would help a lot in this, it seems to me that in the built-in assembly SBCL can be implemented using VOP ( SBCL Internals: VOP ) ( SBCL Internals: adding VOP ), and this IRC journal mentions that ACL (Allegro Common Lisp), CCL (Clozure Common Lisp) and CormanCL have LAP (Lisp Assembly Programs). Both ACLs and CormanCL are proprietary and are thus discarded, but CCL (Clozure Common Lisp) may be one option. One of the tasks is also the ability to create stand-alone executable files; The SBCL I'm using right now has this, but since they are whole Lisp images, their size is quite large.

My question is: can I create a ring0 kernel-mode debugger for Intel x86-64 in Common Lisp, with low-level code implemented in C and / or collection, and if so, which implementations of Common Lisp for 64-bit Linux are best suited for this kind of effort, and what are the pros and cons if there is more than one suitable implementation of Common Lisp? A schema may be one option if it provides some advantages over Common Lisp. I am well aware that the vast majority of kernel modules are written in C, and I know the assembly of C and x86 well enough to be able to write the required low-level code in C and / or assembly. This is not an attempt to port the Linux kernel to Lisp (see https://stackoverflow.com/questions/1848029/why-not-port-linux-kernel-to-common-lisp ), but a plan for writing the Linux kernel module in Common Lisp, which will be used as a debugger ring0.

+7
source share
2 answers

No, it would be impossible to implement the kernel module in CL for the obvious reason that just to make this work, you will need to do a lot of hacks and may lose all the advantages provided by the lisp language and your lisp code will look like C code in S-expressions.

Create your own kernel module to export any functions / data that you need from the kernel, and then with the help of ioctl or read / write operations, any user-mode program can communicate with the module.

I'm not sure if there is any kernel module that is generic enough to implement lisp (or maybe a subset of it), so that you write the code in lisp, and that generic module reads the lisp code and run it as a subcomponent, basically the kernel -> general lisp module -> your lisp code (which will run in the kernel).

+2
source

You might want to take a look at the conversation from September 2, 2008 that Brad Beveridge (Do not Evil Things with Common Lisp) works with the file system driver from SBCL.

Description and discussion files

In it he mentions:

"C / C ++ debugger written in CL?

Currently completely sticking out in the sky

But how great would that be?

Not much, just need to be able to write to the memory where the library is located to insert breakpoints, and then capture signals on the Lisp side

You can use dirty tricks to replace C functions with Lisp function calls

Apart from some details, it may not be that difficult - of course, nothing β€œnew”

The dirty trick involves rewriting C code with another leap (a branch without a link) into a Lisp callback. When the Lisp code returns, it can go directly to the original call function through the link registry.

In addition, I completely ignore the real difficulty of writing a debugger - it will take a lot of time. "

+3
source

All Articles