AT&T code in BSD: an example


by Greg Lehey
Last updated: $Date: 2013/06/18 06:25:57 $

One of the main accusations in the BSD wars of the early 1990s was that BSDI had incorporated AT&T code in their kernel. Rather to our surprise, the accusations turned out to be true. But how important is it? I suppose to a lawyer the presence alone is everything. To a techie, that's another matter. Let's look at an example:

Research UNIX, Seventh Edition

The file sys/clock.c contains the function timeout:
timeout(fun, arg, tim)
int (*fun)();
caddr_t arg;
{
    register struct callo *p1, *p2;
    register int t;
    int s;

    t = tim;
    p1 = &callout[0];
    s = spl7();
    while(p1->c_func != 0 && p1->c_time <= t) {
        t -= p1->c_time;
        p1++;
    }
    if (p1 >= &callout[NCALL-1])
        panic("Timeout table overflow");
    p1->c_time -= t;
    p2 = p1;
    while(p2->c_func != 0)
        p2++;
    while(p2 >= p1) {
        (p2+1)->c_time = p2->c_time;
        (p2+1)->c_func = p2->c_func;
        (p2+1)->c_arg = p2->c_arg;
        p2--;
    }
    p1->c_time = t;
    p1->c_func = fun;
    p1->c_arg = arg;
    splx(s);
}

FreeBSD release 1.0

The file sys/kern/kern_clock.c contains the function timeout:
/*
 * Arrange that (*func)(arg) is called in t/hz seconds.
 */
timeout(func, arg, t)
    int (*func)();
    caddr_t arg;
    register int t;
{
    register struct callout *p1, *p2, *pnew;
    register int s = splhigh();

    if (t <= 0)
        t = 1;
    pnew = callfree;
    if (pnew == NULL)
        panic("timeout table overflow");
    callfree = pnew->c_next;
    pnew->c_arg = arg;
    pnew->c_func = func;
    for (p1 = &calltodo; (p2 = p1->c_next) && p2->c_time < t; p1 = p2)
        if (p2->c_time > 0)
            t -= p2->c_time;
    p1->c_next = pnew;
    pnew->c_next = p2;
    pnew->c_time = t;
    if (p2)
        p2->c_time -= t;
    splx(s);
}

The FreeBSD example is identical to the version in 4.3BSD, with one minor exception: in 4.3BSD the parameter func is called fun. Comparing these two functions, it's clear that they're related. Even the variable names are the same. But is this rocket science? We're working our way through the timeout list, whose structure hasn't changed much in the intervening time.

In comparison, Linux kernel structures are very different, and such a carryover wouldn't have been possible.


$Id: unix-in-BSD.php,v 1.2 2013/06/18 06:25:57 grog Exp $

Valid XHTML 1.0!