Messing with 0 ptr on m68020 & sys V / 68

Riku Kalinen riku at clinet.FI
Sat Nov 26 00:18:21 AEST 1988


First of all: I know, that messing around with 0 pointers is asking of
trouble. The following is kinda intresting, however..

Hardware: Motorola 8400 business - unix box with m68020
Software: System V / 68 ver. 5.3.1 (?) [ Sys V rel 3 ]

When i run the following program, it gives me 1024 '\0':s and then core dump
(when offset gets into 1024). 

Seems that my process's address space contains 1 k read-only nulls in
very beginnig.

Questions:
  1) Why? This causes reference thru 0 ptr to return 0 instead of core dump.
     (Of course, if I try to write something there, everything crashes as it
      should.)
  2) Who sets up process's memory when it is started? Kernel?
  3) Is there any good reasons to do this.

/* --- clip --- clip --- clip --- */

/* baz.c - mess around with null pointer. */

#include <stdio.h>
#include <ctype.h>

main()
{
  register char *base = 0;
  register unsigned long offset;
  register char ch;

  for (offset = (unsigned long) 0; offset < (unsigned long) 2000; offset ++)
    {
      cha = *(base + offset); /* dumps core when offset == 1024 == 1k */
      printf ("%04lx = %d\n", offset, (int) cha);
    }
}

/* --- clip --- clip --- clip --- */

Please send responses via email, I'll summarize if I get something usable.

And, PLEASE, PLEASE don't tell me this should never be done.
I know it already, but sometimes it is fun to try something impossible 8-) .


-- 
Riku "the bit" Kalinen                    Internet      : riku at clinet.FI
                                          Elisa/s.mail  : funet:riku at clinet.fi
City Lines Inc, Helsinki, Finland         Telephone int : +358 0 694 1056
    -- "..We are what we are and it's never enough.." (Chris de Burgh) --



More information about the Comp.lang.c mailing list