Re: C++ in kernel (was Re: exception in a device driver)

Oliver Xymoron (oxymoron@waste.org)
Mon, 11 Jan 1999 18:43:37 -0600 (CST)


On Mon, 11 Jan 1999, Chip Salzenberg wrote:

> According to Anthony Barbachan:
> > The problem with exceptions (especially in the kernel):
> >
> > 1 - Error probably not handled locally in function, meaning the
> > function is relying on some higher level code to take care of the
> > exceptions.
>
> You may not realize that this is already true in C. In C the kernel
> says e.g. 'return -ENOENT'. That's not 'handling' the error at all!
> It's just *reporting* the error.
>
> Replace the 'return' with a 'throw' in C++, and nothing's different,
> except that it's effectively a multi-stack-frame return that's used
> to _report_ errors.

Not anywhere near that simple. Having exceptions anywhere in the kernel
would require protecting basically every critical section with exception
handling (much worse than the current small number of spinlocks) to avoid
leaving data/hardware/spinlocks in an inconsistent state when a function
unexpectedly decides to throw an exception and unroll the stack before the
caller's had a chance to reenable interrupts, clean up dangling pointers,
etc... Bug tracking nightmare, not to mention major code bloat. Better off
oopsing. You don't have this problem in C, because it's safe to assume
that functions WILL return to the caller.. Exceptions are not your friend.

--
 "Love the dolphins," she advised him. "Write by W.A.S.T.E.." 

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/