Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
Programming Operating Systems BSD IT Technology

Adding System Calls (an OpenBSD Example) 19

BSD Forums writes "Kernel programming sometimes feels like a dark art where application programmers should never venture, but sometimes it's the right way to solve a problem. (Oh, and it's also very interesting.) One of the easiest places to start is by adding a new system call to a kernel. Kevin Lo explains how and why, with the OpenBSD kernel in this OnLamp article."
This discussion has been archived. No new comments can be posted.

Adding System Calls (an OpenBSD Example)

Comments Filter:
  • other examples (Score:4, Informative)

    by fred ugly ( 125371 ) <fugilyfredNO@SPAMhotmail.com> on Friday October 10, 2003 @09:35AM (#7182253)
    A simple Google search [google.com] brings up plenty of info on how to do this in Linux as well...
  • by Anonymous Coward
    I think my last attempt at 'hello-world' may have introduced a local root hole. Kernel hacking is probably knowledge I shouldn't have ... I'm sure I'm not alone =)
  • by John Sokol ( 109591 ) on Friday October 10, 2003 @11:27AM (#7183281) Homepage Journal
    I have done this several times in the past and what happens is you then have an application trapped on a non-standard system. Any system that it runs that application will need your kernal patch with the new calls.

    This gets even worse when the OS keeps upgrading and you are forced to migrate your changes up to be able to use current hardware. (this is need when all of the supported hardware is no longer available new)

    In practice it turn into a major undertaking everytime a new OS release came out.

    It's is a cool thing to have fun with. But think twice before you base a product or application on a kernel change. (unless you can get the main development tree to adopt it.) Or have the resources to maintain your own OS development team.

    Adding new syscontrols and sockopts are also great fun.

    At one point we had a versions of FreeBSD that could run DES encrypted Binaries, access the hard driver serial numbers and Mount a CD from HTTP or FTP connection, transmit Datagrams masquerading as TCP connections and be able to process Router Alert packets.

    John
    • An excellent point.

      I wrote patches to the linux kernel and apache to allow all PHP and CGI requests to run as the owner of the file being requested. Actually the UID changes for each request, even static pages. So long as a stat() can be done it should work. This means the files don't have to be readable by the webserver.

      The system stores the user ID on a stack and returns to the webserver user ID when the request has been served so no forking or set-uid files are needed. (Yes root needs to configure
  • Awesome, we'll get even more syscalls! Linus is going to love this..
    • Awesome, we'll get even more syscalls! Linus is going to love this..

      The article is about syscalls in the OpenBSD kernel. I don't think that Linus is very interested in recieving patches for new syscalls in a BSD kernel.

  • Now, I know the code in the article is only sample code, and as such need not be perfect as long as it gets its point across. I'd say it does that just fine, it was an interesting read. But I can't help feel a bit saddened by code such as this snippet:

    size_t len;
    char buffer[1024]; /* must bounds check all user values */
    if (SCARG(uap, len) > (size_t)1024)
    return(EINVAL);

    Here, the author needlessly repeats the "1024" constant, which introduces a fine opportunity to make an error by only changing the

    • " There are no parens involved, since neither sizeof nor return are function calls. This seems to be a matter of personal style, though"

      Its not just a case of personal taste , using sizeof with parenthesis will only work for types that only have a 1 token declaration

      Eg: sizeof int

      works fine , whereas

      sizeof int * sizeof struct foo

      will give an error with most compilers. So in this sense the sizeof operator is not treated
      syntatically in an equivalent way to the return operator. Just anothe
      • Missed out a newline

        sizeof int *
        sizeof struct foo

        should have been seperate.
      • I wasn't being complete since I wanted to, er, not sound too dorky. The sizeof operator takes a single argument, that's true. If the argument is to be a type name, such as int or your struct foo, then that type name needs to be a cast expression, which as we all know is simply the type name in parens. Using a type name without parens is, as far as I know, a syntax error.

He has not acquired a fortune; the fortune has acquired him. -- Bion

Working...