[comp.os.minix] kmem bug, partial fix

brucee@runx.ips.oz (Bruce Evans) (11/16/88)

In kernel/memory.c, the initialization of ram_limit[KMEM_DEV] fails as soon
as the kernel text+data+bss exceeds 64K. A fix is enclosed.

This should have caused /dev/kmem to be empty on my system, but there are
bugs in fs which cause it to read as infinite garbage instead. (Try
"od /dev/kmem".) do_mem() returns 0 for end of file. The problem is in
fs/cache.c/rw_block() which does not report errors directly to its caller.
Returning EOF in do_mem() as for /dev/ram would work better but there are
probably still bugs with the way FS treats this EOF (returning it to
the user instead of converting it to 0). /dev/mem is not infinite. It is
limited to 640K by some test I haven't located.

The diff also includes the elimination of the machine-dependent get_base()
from the kernel. Using get_base() defeats the purpose of having umap().
This was necessary for my 386 port. There was similar dirt in fs/main.c
which was replaced by a call to umap() via the system task.

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  memory.c.cdif
# Wrapped by sys@besplex on Wed Nov 16 03:54:29 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'memory.c.cdif' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'memory.c.cdif'\"
else
echo shar: Extracting \"'memory.c.cdif'\" \(1235 characters\)
sed "s/^X//" >'memory.c.cdif' <<'END_OF_FILE'
X*** /user/sys/kernel/memory.c	Thu Oct  6 21:07:43 1988
X--- memory.c	Wed Nov 16 02:03:40 1988
X***************
X*** 46,57 ****
X  
X    int r, caller, proc_nr;
X    extern unsigned sizes[8];
X!   extern phys_clicks get_base();
X! 
X! 
X!   /* Initialize this task. */
X!   ram_origin[KMEM_DEV] = (phys_bytes) get_base() << CLICK_SHIFT;
X!   ram_limit[KMEM_DEV] = (sizes[0] + sizes[1]) << CLICK_SHIFT;
X    ram_limit[MEM_DEV] = MEM_BYTES;
X  
X    /* Here is the main loop of the memory task.  It waits for a message, carries
X--- 46,57 ----
X  
X    int r, caller, proc_nr;
X    extern unsigned sizes[8];
X!   extern phys_bytes umap();
X! 
X!   /* Initialize this task. */
X!   ram_origin[KMEM_DEV] = umap(proc_addr(SYSTASK), D, (vir_bytes) 0,
X!                               (vir_bytes) 1);
X!   ram_limit[KMEM_DEV] = (phys_bytes) (sizes[0] + sizes[1]) << CLICK_SHIFT;
X    ram_limit[MEM_DEV] = MEM_BYTES;
X  
X    /* Here is the main loop of the memory task.  It waits for a message, carries
X***************
X*** 93,99 ****
X    int device, count, words, status;
X    phys_bytes mem_phys, user_phys;
X    struct proc *rp;
X-   extern phys_clicks get_base();
X    extern phys_bytes umap();
X  
X    /* Get minor device number and check for /dev/null. */
X--- 93,98 ----
END_OF_FILE
if test 1235 -ne `wc -c <'memory.c.cdif'`; then
    echo shar: \"'memory.c.cdif'\" unpacked with wrong size!
fi
# end of 'memory.c.cdif'
fi
echo shar: End of shell archive.
exit 0

Bruce Evans
Internet: brucee@runx.ips.oz.au    UUCP: uunet!runx.ips.oz.au!brucee