4.3BSD/usr/contrib/kermit/ckuv7.hlp

Date:     Fri, 17 May 85 18:53:43 CDT
From:     Gregg Wonderly <gregg@okstate.csnet>
Subject:  Additional C-Kermit Implementation Notes for Version 7 UNIX

     The Version 7 implementation takes advantage of some information present
in the UNIX kernal to obtain the count of characters available for input from
a particular file descriptor.  The function initrawq() is used to obtain the
kernal address of this value.  It is a structure value that is associated with
the clist for the file descriptor passed.  The struture member is the "rawq"
count of characters available.  The include file <sys/clist.h> on our system
shows this value as the first "int" in the structure.  The operations in
initrawq() cause the child process to "block", trying to read from the "tty"
file descriptor.  Then, by looking through the "proc" structures, we find the
proper process, and get its "wchan" pointer.  This is a pointer to the clist
in question, in the kernal memory.

     The "wchan" address can then be used as an offset by lseek to select the
proper address in the kernal (/dev/kmem) to read from.  By reading the first
"int" at this address, we obtain a count of the characters available on the
raw input queue.

     The MAKE variables PROC, NPROCNAME, BOOTNAME, are necessary to get around
different naming conventions across systems.  The variable PROC is the name
given to the process structure array on your system.  The include file <sys/
proc.h> (or some facsimile) should contain a declaration of the form:

     extern struct proc *proc;
or
     extern struct proc proc[];

The name of the pointer/array, is what you are concerned with.  It may be
something like "_proc", "proc", or some deriviation.  You should define
the MAKE variable PROC to this string, whatever it may be.  On our system,
I use "PROC=proc".  If your definition is for an array, then you should define
the MAKE variable DIRECT to be "-DDIRECT", as it is in the MAKEFILE.  If your
definition is for a pointer to the array, then you should remove the definition
of DIRECT, so the the line reads "DIRECT=" (no value here).  This is necessary
for the routine to properly locate the "proc" array.  If you have an array
declaration, then the call to nlist() will return the address of the array.
However, if you have a pointer, then nlist() returns the address of the
pointer.  This requires one extra level of dereference to obtain the address of
the array.

     The same thing applies to the variable NPROCNAME.  On our system, this is
defined as "NPROCNAME=nproc".  This should also be declared in <sys/proc.h>
something like:

     extern int nproc;

This value is the number (Maximum that is) of process entries in the "proc"
array.

     BOOTNAME is the name of the kernal image on your system.  On our system,
it is "/edition7".  On others, it is probably "/unix", or something close.
The nlist() function uses this file to look for the addresses of the kernal
variables "proc", and "nproc".