DragonFly BSD
DragonFly kernel List (threaded) for 2004-03
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

proposed patch to improve seperation between kernel and userland code


From: Chris Pressey <cpressey@xxxxxxxxxxxxxxx>
Date: Sun, 14 Mar 2004 17:40:29 -0800

The attached patch probably deserves some discussion, so I'm posting it
here first rather than straight to the submit list.

The idea is to enhance the distinction between kernel source code and
userland source code.  (This started as sort of an offshoot of removing
parameter names from function protoypes in userland-accessible headers.)

You may well ask if this is a good idea, especially considering that one
of the goals of DragonFly is to be able to run some stuff that's
traditionally in-kernel, in the userland instead.

But I do think it is a good idea, since the procedure and environment
for building the kernel code will still be different from the procedure
and environment for building userland stuff.  Increasing the isolation
between the two at the source code level, by making it explicit which
code is kernel code, is IMO a good move from a software engineering
perspective.  I'm open to reasoned discussion on this, of course.

The two rules I'm following to make this idea happen are:

	- If a userland program needs definitions of internal kernel
	  structures, it *must* define _KERNEL_STRUCTURES; and
	- if a header in sys/ exposes kernel function prototypes, it
	  *must* surround them with #ifdef _KERNEL.

So in this patch, I implemented the rules in twenty sys/ headers, and
repeatedly tried building world until it could be built without errors. 
The problems I fixed during this, also included in the patch, are:

	- disconnect libdisk from buildworld.
	- #define _KERNEL_STRUCTURES in lib/libkvm/kvm_getswapinfo.c.
	- Move placement of #define _KERNEL in sys/bus/cam/scsi/scsi_da.c
	  to encompass two more header files.
	- add "#define _KERNEL_STRUCTURES" to mkioctls script (used when
	  building kdump, ktrace, and truss.)
	- move 'ntp' to it's (alphabetically) proper place in the Makefile.

Really, not that much.  I also made two headers (dir.h & timers.h)
outright obsolete, and took two useless prototypes out of diskmbr.h, and
made assorted style changes (in comments).  And my world builds fine.

I haven't tried building for archs other than i386, though, so there
might yet be rough spots.

Another big rough spot will be the ports tree.  I fully expected lsof to
break; in fact, it was already broken!  I'm working on an override port.
The wait_on port works; as I think of more ports which depend on
(Free|DragonFly)BSD-specific features, I'll try to test them too.
Suggestions are quite welcome...

-Chris

Attachment: _kernel_structures.diff.gz
Description: Binary data



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]