Slashdot Mirror


Schemix - A Scheme In The Linux Kernel

Phs2501 writes "Schemix is a Scheme running in the Linux kernel. It presents /dev/schemix to send Scheme forms to, and has extensions to read and set (C) kernel variables, call kernel functions, and make devices. If you've wanted to prototype your drivers in a high-level language that's 100% in the kernel, here you go."

1 of 58 comments (clear)

  1. The Schemix home page by halfnerd · · Score: 0, Redundant

    Schemix

    Schemix is a Scheme system, implemented as a patch to the Linux kernel. It aims to attain R5RS compliance while remaining small, fast and easy to understand.

    The intended use of Schemix is for exploration of the Linux kernel and for rapid, interactive prototyping of Linux drivers and other new kernel features. To achieve this, Schemix will attempt to make a large subset of the kernel functionality available to Scheme programs. Interactivity is via a character device, /dev/schemix which presents a REPL (Read, Eval, Print Loop) to anyone having access to the device.

    Schemix is based on a stripped-down and modified version of TinyScheme. Currently the system can be successfully compiled into a 2.4.x kernel, which then reads and executes Scheme code from /dev/schemix. Any output is written to /dev/schemix.

    The following is a short example of a Schemix session (colour coded to make it easier to read):

    $ cat /dev/schemix

    $ echo "(display (+ 1 2 3))" > /dev/schemix
    $ cat /dev/schemix
    6
    $ cat > /dev/schemix
    (define foo (kernel-lambda (char*) printk))
    (foo "Blah, blah, blah")

    $ dmesg | tail -n 1
    Blah, blah, blah
    $ echo "(make-device foo ((a 1) (b 2)))" > /dev/schemix
    $ ls -l /dev/foo
    crw------- 1 root root 10, 1 Mar 31 14:09 /dev/foo
    $ echo "(display a)" > /dev/foo
    $ cat /dev/foo
    1
    $ echo "(display a)" > /dev/schemix
    $ cat /dev/schemix
    Error: eval: unbound variable: a
    $ echo "(exit)" > /dev/foo
    $ ls -l /dev/foo
    ls: /dev/foo: No such file or directory
    $ # the following assumes there is an exported variable 'int blah' in the kernel source.
    $ echo "(define read-blah (kernel-getter (int) blah))" > /dev/schemix
    $ echo "(define write-blah (kernel-setter (int) blah))" > /dev/schemix
    $ echo "(display (read-blah))" > /dev/schemix
    $ cat /dev/schemix
    0
    $ echo "(write-blah 42)" > /dev/schemix
    $ echo "(display (read-blah))" > /dev/schemix
    $ cat /dev/schemix
    42

    The most frequently asked question about Schemix is 'why?'. This is good. People should always ask 'why?' when something gets pushed from user-space into kernel-space. There are things about the Scheme language though, that make it a Good Thing to have in the kernel:

    * Scheme is a very safe language. It doesn't allow you to create arbitrary pointers or over-run buffers. If you divide by zero, the universe will not end. This makes it a good language for prototyping, because prototyping is basically the act of making lots of mistakes until, eventually, you make the right mistake and call it a finished product.
    * Schemix is small. It adds very little overhead to a kernel but provides lots of power and flexibility.
    * Schemix can be very secure. If you are brave enough to use Schemix in a production system you can shut down the /dev/schemix REPL by doing 'echo "(exit)" > /dev/schemix'. Also, if you don't use any of the kernel-* functions provided by Schemix and just stick to R5RS Scheme, you should never be able to crash the kernel.
    * It's fun

    The current release of Schemix (2.4.20) can be downloaded from here

    Features that are planned but not yet implemented:

    * The special forms kernel-getter and kernel-setter will be extended to allow getting and setting of multi-dimensional variables, e.g.
    o (kernel-getter (char* 1024) foo) ; foo is a string with maximum length 1024
    o (kernel-setter (int** 50 50) bar) ; bar is a two-dimensional array of ints (50 x 5