can python do some kernel stuff?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sturlamolden

    #16
    Re: can python do some kernel stuff?

    On Jun 4, 12:41 am, Ethan Furman <et...@stonelea f.uswrote:
    the kernel itself, *is* kernel coding. And as wonderful as Python is,
    it is *not* for kernel coding.
    Not in its present form, no, it would take some porting. But aside
    from that, is there any reason one could not embed a python
    interpreter in the kernel?

    Comment

    • Grant Edwards

      #17
      Re: can python do some kernel stuff?

      >The answer is yes. IPC and py-pf are examples. If you don't
      >think of packet filtering as kernel coding, I can understand.
      >But clearly the Python interfaces to fork(), waitpid(),
      >signal(), alarm() and so forth are forays into the once
      >private garden of C.
      The routines listed above aren't in the kernel. They're in
      libc just like routines such as printf, memcpy, etc. The above
      libc routines do make system calls into the kernel to perform
      the desired functions, but those routines are not in the
      kernel, and calling them is certainly not "kernel coding".

      Yes, Python provides specific wrappers for many C library
      functions.

      Yes, the ctypes module provides a generic method for calling
      foreign library functions.

      No, using those wrappers is not what anybody I know would call
      "kernel coding".
      Being able to call routines in the kernel is *not* the same as
      kernel coding.
      As far as I know, Python doesn't provide the user with the
      ability to make system calls into the kernel. Even if it did,
      that isn't really "kernel coding" either. It's just making
      system calls.
      Calling C routines is *not* the same as kernel coding.
      Actually writing the routines that are to be called, and that
      constitute the kernel itself, *is* kernel coding. And as
      wonderful as Python is, it is *not* for kernel coding.
      >
      Having just looked at Py-PF, it is *managing* the firewall,
      not implementing it. Again, not kernel coding.
      Didn't somebody once demonstrate how to put a VM into kernel
      space so that you could write kernel code in Python? Maybe it
      was just a discussion about how it could be done in theory.

      There have been a few JVM-in-hardware projects, so I suppose
      you could use Jython to write kernel code for those machines.

      --
      Grant Edwards grante Yow! I have accepted
      at Provolone into my life!
      visi.com

      Comment

      • Ivan Illarionov

        #18
        Re: can python do some kernel stuff?

        On Wed, 04 Jun 2008 09:41:07 -0500, Grant Edwards wrote:
        >>The answer is yes. IPC and py-pf are examples. If you don't think of
        >>packet filtering as kernel coding, I can understand. But clearly the
        >>Python interfaces to fork(), waitpid(), signal(), alarm() and so forth
        >>are forays into the once private garden of C.
        >
        The routines listed above aren't in the kernel. They're in libc just
        like routines such as printf, memcpy, etc. The above libc routines do
        make system calls into the kernel to perform the desired functions, but
        those routines are not in the kernel, and calling them is certainly not
        "kernel coding".
        >
        Yes, Python provides specific wrappers for many C library functions.
        >
        Yes, the ctypes module provides a generic method for calling foreign
        library functions.
        >
        No, using those wrappers is not what anybody I know would call "kernel
        coding".
        >
        >Being able to call routines in the kernel is *not* the same as kernel
        >coding.
        >
        As far as I know, Python doesn't provide the user with the ability to
        make system calls into the kernel. Even if it did, that isn't really
        "kernel coding" either. It's just making system calls.
        >
        >Calling C routines is *not* the same as kernel coding. Actually writing
        >the routines that are to be called, and that constitute the kernel
        >itself, *is* kernel coding. And as wonderful as Python is, it is *not*
        >for kernel coding.
        >>
        >Having just looked at Py-PF, it is *managing* the firewall, not
        >implementing it. Again, not kernel coding.
        >
        Didn't somebody once demonstrate how to put a VM into kernel space so
        that you could write kernel code in Python? Maybe it was just a
        discussion about how it could be done in theory.
        >
        There have been a few JVM-in-hardware projects, so I suppose you could
        use Jython to write kernel code for those machines.
        I can't understand why somebody might want to do kernel stuff in Python.
        It's a *high level language*. It's for high level stuff.

        OTOH Python can be easily extended to get as close to the kernel as
        anyone may ever need.

        I decided to change my "hello world" post to use Linux system call
        instead of printf.

        #include <Python.h>

        PyObject*
        hello(PyObject* self)
        {
        #if defined(__GNUC_ _) && defined(__i386_ _) && defined(__linux __)
        const char * hello_str = "Hello world (Linux system call)!\n";
        int hello_len = 33;
        asm __volatile__(
        "push %%ebx;"
        "movl $4, %%eax;" /* The system call for write (sys_write) */
        "movl $1, %%ebx;" /* File descriptor 1 - standard output */
        "int $0x80;"
        "pop %%ebx;"
        : /* no outputs */
        : "c" (hello_str), "d" (hello_len) /* input */
        );
        #else
        printf("Hello world!\n");
        #endif
        Py_RETURN_NONE;
        }

        static PyMethodDef functions[] = {
        {"hello", (PyCFunction)he llo, METH_NOARGS},
        {NULL, NULL, 0, NULL},
        };

        DL_EXPORT(void)
        init_hello(void )
        {
        Py_InitModule(" _hello", functions);
        }

        Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42)
        [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
        Type "help", "copyright" , "credits" or "license" for more information.
        >>from _hello import hello
        >>hello()
        Hello world (Linux system call)!

        I'm in the mood to write "Hello world" programs today ;)

        Ivan

        Comment

        • Grant Edwards

          #19
          Re: can python do some kernel stuff?

          On 2008-06-04, Ivan Illarionov <ivan.illariono v@gmail.comwrot e:
          >Didn't somebody once demonstrate how to put a VM into kernel
          >space so that you could write kernel code in Python? Maybe it
          >was just a discussion about how it could be done in theory.
          >>
          >There have been a few JVM-in-hardware projects, so I suppose
          >you could use Jython to write kernel code for those machines.
          >
          I can't understand why somebody might want to do kernel stuff
          in Python.
          we choose to put Python in kernel-space and do the other
          things, not because they are easy, but because they are
          hard, because that goal will serve to organize and measure
          the best of our energies and skills...

          ;)
          It's a *high level language*. It's for high level stuff.
          There is a lot of high-level stuff in the kernel. Performance
          expectations and resource availability don't make python
          and the PVM a very practical choice.
          OTOH Python can be easily extended to get as close to the kernel as
          anyone may ever need.
          >
          I decided to change my "hello world" post to use Linux system call
          instead of printf.
          >
          #include <Python.h>
          >
          PyObject*
          hello(PyObject* self)
          {
          #if defined(__GNUC_ _) && defined(__i386_ _) && defined(__linux __)
          const char * hello_str = "Hello world (Linux system call)!\n";
          int hello_len = 33;
          asm __volatile__(
          "push %%ebx;"
          "movl $4, %%eax;" /* The system call for write (sys_write) */
          "movl $1, %%ebx;" /* File descriptor 1 - standard output */
          "int $0x80;"
          "pop %%ebx;"
          : /* no outputs */
          : "c" (hello_str), "d" (hello_len) /* input */
          );
          #else
          printf("Hello world!\n");
          #endif
          Py_RETURN_NONE;
          }
          >
          static PyMethodDef functions[] = {
          {"hello", (PyCFunction)he llo, METH_NOARGS},
          {NULL, NULL, 0, NULL},
          };
          >
          DL_EXPORT(void)
          init_hello(void )
          {
          Py_InitModule(" _hello", functions);
          }
          >
          Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42)
          [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
          Type "help", "copyright" , "credits" or "license" for more information.
          >>>from _hello import hello
          >>>hello()
          Hello world (Linux system call)!
          >
          I'm in the mood to write "Hello world" programs today ;)
          That's cool. A generic Linux syscall wrapper for Python
          wouldn't be hard to do. Though I'm not sure what the practical
          uses would be.

          --
          Grant Edwards grante Yow! OVER the underpass!
          at UNDER the overpass!
          visi.com Around the FUTURE and
          BEYOND REPAIR!!

          Comment

          • Ivan Illarionov

            #20
            Re: can python do some kernel stuff?

            On Wed, 04 Jun 2008 11:24:11 -0500, Grant Edwards wrote:
            >I can't understand why somebody might want to do kernel stuff in
            >Python.
            >
            we choose to put Python in kernel-space and do the other things, not
            because they are easy, but because they are hard, because that goal
            will serve to organize and measure the best of our energies and
            skills...
            >
            ;)
            tinypy rewritten in assembly probably could do the kernel job. CPython is
            far too big for the kernel.

            Another crazy idea. What about initd/launchd replacement in pure Python?
            Python would be the first PID. Isn't it more practical?

            Ivan

            Comment

            • Tim Roberts

              #21
              Re: can python do some kernel stuff?

              sturlamolden <sturlamolden@y ahoo.nowrote:
              >
              >On Jun 4, 12:41 am, Ethan Furman <et...@stonelea f.uswrote:
              >
              >the kernel itself, *is* kernel coding. And as wonderful as Python is,
              >it is *not* for kernel coding.
              >
              >Not in its present form, no, it would take some porting. But aside
              >from that, is there any reason one could not embed a python
              >interpreter in the kernel?
              Not at all. Microsoft Research has issued a preview release of an
              operating system called "Singularit y" where the entire kernel and all
              drivers are written as managed code. Since Python can now be used to write
              managed code (via IronPython), Q.E.D.
              --
              Tim Roberts, timr@probo.com
              Providenza & Boekelheide, Inc.

              Comment

              Working...