tech-kern archive

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

Re: NULL pointer arithmetic issues

On 2020-02-25 12:33, Tom Ivar Helbekkmo wrote:
Johnny Billquist <> writes:

But yes, on the PDP11 [having nothing mapped at address 0] was/is not
the case. Memory space is too precious to allow some of it to be
wasted for this...

Yup - and I assume the "hack" Kamil alludes to is the practice of
actually starting the data segment for split I/D programs at address 1
instead of 0, to make sure that no actual pointer is 0, thus allowing
the straightforward comparison of a pointer with 0 to see if it's set.

Well, the d-dpace don't start at 1, and also, the PDP-11 isn't that fond of odd addresses. :-)
Actually, you could not even start a page at address 1 if you wanted.

(I believe they also initialized address 0 to 0, to stop indirect
references through it from reaching random data.  I guess Franz may have
depended on this in some way, e.g. expecting to be able to test *p
directly, instead of first p and then *p.  Do enough of this, and you've
soon bummed a significant amount of valuable code space...)

It used to, but not for some time now.

Here is the current "state":

 * Paragraph below retained for historical purposes.
* The following zero has a number of purposes - it serves as a null terminated
 * string for uninitialized string pointers on separate I&D machines for
 * instance.  But we never would have put it here for that reason; programs
* which use uninitialized pointer *should* die. The real reason it's here is
 * so you can declare "char blah[] = "foobar" at the start of a C program
 * and not have printf generate "(null)" when you try to print it because
* blah is at address zero on separate I&D machines ... sick, sick, sick ...
 * In porting bits and pieces of the 4.4-Lite C library the global program
 * name location '___progname' was needed.  Rather than take up another two
 * bytes of D space the 0th location was used.   The '(null)' string was
 * removed from doprnt.s so now when programs use uninitialized pointers
 * they will be rewarded with argv[0].  This is no sicker than before and
 * may cause bad programs to die sooner.
        .globl  ___progname, _strrchr

___progname: 0


Johnny Billquist                  || "I'm on a bus
                                  ||  on a psychedelic trip
email:             ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol

Home | Main Index | Thread Index | Old Index