Newsgroups: comp.os.minix
Subject: Re: Paternalistic null pointer code?
References: <3b0a8365.0@news.syr.edu> <nt248cbes465pas49q6looc052@stereo.pch.home.cs.vu.nl> <cicge9.vl6.ln@jetsam.cs.vu.nl>
Organization: Syracuse University, Syracuse
From: mcconnel@hydra.syr.edu (Terry R. McConnell)
NNTP-Posting-Host: hydra.syr.edu
Message-ID: <3b0d26d7.0@news.syr.edu>
Date: 24 May 2001 11:20:55 -0500
X-Trace: 24 May 2001 11:20:55 -0500, hydra.syr.edu
Lines: 60
Path: news.adfa.edu.au!clarion.carno.net.au!news0.optus.net.au!news1.optus.net.au!optus!news-out.cwix.com!newsfeed.cwix.com!news.maxwell.syr.edu!news.syr.edu!hydra.syr.edu!mcconnel
Xref: news.adfa.edu.au comp.os.minix:37432

In article <cicge9.vl6.ln@jetsam.cs.vu.nl>,
Kees J Bot <kjb=732508@cs.vu.nl> wrote:
>In article <nt248cbes465pas49q6looc052@stereo.pch.home.cs.vu.nl>,
>Philip Homburg <philip@pch.home.cs.vu.nl> wrote:
>>In article <3b0a8365.0@news.syr.edu>,
>>Terry R. McConnell <mcconnel@hydra.syr.edu> wrote:
>>

[ concerning my ongoing attempt to port lcc/GNU binutils. ]

>>
>>I guess, your compiler is defective. The address of a variable should not
>>be a null pointer.
>
>The only reason this doesn't happen under ACK is that crtso.s contains a
>few .rom/.data elements that are loaded first.  If you believe that
>crtso.s is part of the compiler then this problem is indeed a compiler
>bug.
>

Thanks for clarifying this. I hadn't yet translated crtso.s into AT&T syntax,
figuring I should get to point where I could print stuff out first in order
to be able to test whether argv, envp, etc were being set up correctly. I was
only linking a baby crtso.s that just called main and then _exit.

I have a couple more questions now that I've had time to study the crtso.s 
code somewhat:

1) The code begins with

xor ebp, ebp
mov ebx, (esp)
mov ecx, 4(esp)

and eventually ebx, ecx are pushed on the stack just before calling _main. It
appears that ebx now should contain argc, but according to the discussion of
the exec system call in the textbook, the last thing on the stack created by
exec before passing it to MM is argv. There's no argc that I can see. Is this
just a mistake in the text?

2) I'm having sort of hard time following the setup of envp. I guess it ends up
either pointing to stuff on the stack originally passed by the shell to exec, 
or else to a static block in the initialized data segment. Is that right? 
The code comments seem to indicate that in the latter case "our" block in
the data segment is marked with a magic number. I'm assuming "we" is the
compiler and that this case would occur if the user program had something
like

extern char **environ;
....
static char *foo[] = {"HOME=/usr/ast\0",NULL};  
environ = foo;

Is there any other way this case can happen?

-- 
************************************************************************
Terry R. McConnell   Mathematics/304B Carnegie/Syracuse, N.Y. 13244-1150
trmcconn@syr.edu     http://barnyard.syr.edu/~tmc    Question Authority?
************************************************************************
