The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] A few comments on porting the Bourne shell
@ 2022-12-30 18:25 Paul Ruizendaal
  2022-12-30 19:51 ` [TUHS] " Chet Ramey
  2022-12-30 19:57 ` segaloco via TUHS
  0 siblings, 2 replies; 99+ messages in thread
From: Paul Ruizendaal @ 2022-12-30 18:25 UTC (permalink / raw)
  To: The Eunuchs Hysterical Society


London and Reiser report about porting the shell that “it required by far the largest conversion effort of any supposedly portable program, for the simple reason that it is not portable.” By the time of SysIII this is greatly improved, but also in porting the SysIII user land it was the most complex of the set so far.

There were three aspects that I found noteworthy:

1. London/Reiser apparently felt strongly about a property of casts. The code argues that casting an l-value should not convert it into a r-value:

<quote from "mode.h">
/* the following nonsense is required
 * because casts turn an Lvalue
 * into an Rvalue so two cheats
 * are necessary, one for each context.
 */
union { int _cheat;};
#define Lcheat(a)	((a)._cheat)
#define Rcheat(a)	((int)(a))
<endquote>

However, Lcheat is only used in two places (in service.c), to set and to clear a flag in a pointer. Interestingly, the 32V code already replaces one of these instances with a regular r-value cast. So far, I’d never thought about this aspect of casts. I stumbled across it, because the Plan 9 compiler did not accept the Lcheat expansion as valid C.

2. On the history of dup2

The shell code includes the following:

<quote from “io.c”>
rename(f1,f2)
	REG INT		f1, f2;
{
#ifdef RES	/*	research has different sys calls from TS	*/
	IF f1!=f2
	THEN	dup(f1|DUPFLG, f2);
		close(f1);
		IF f2==0 THEN ioset|=1 FI
	FI
#else
	INT	fs;
	IF	f1!=f2
	THEN 	fs = fcntl(f2,1,0);
		close(f2);
		fcntl(f1,0,f2);
		close(f1);
		IF fs==1 THEN fcntl(f2,2,1) FI
		IF f2==0 THEN ioset|=1 FI
	FI
#endif
}
<endquote>

I’ve check the 8th edition source, and indeed it supports using DUPFLG to signal to dup() that it really is dup2(). I had earlier wondered why dup2() did not appear in research until 10th edition, but now that is clear. It would seem that the dup of 8th edition is a direct ancestor to dup() in Plan 9. I wonder why this way of doing things never caught on in the other Unices.

3. Halfway to demand paging

I stumbled across this one because I had a bug in my signal handling. From early days onwards, Unix supported dynamically growing the stack allocation, which arguably is a first step towards building the mechanisms for demand paging. It appears that the Bourne shell made another step, catching page faults and expanding the data/bss allocation dynamically:

<quote from “fault.c”>
VOID	fault(sig)
	REG INT		sig;
{
	signal(sig, fault);
	IF sig==MEMF
	THEN	IF setbrk(brkincr) == -1
		THEN	error(nospace);
		FI
	ELIF ...
<endquote>

This was already present in 7th edition, so it is by no means new in 32V or SysIII -- it had just escaped my attention as a conceptual step in the development of Unix memory handling.




^ permalink raw reply	[flat|nested] 99+ messages in thread

end of thread, other threads:[~2023-01-11  3:53 UTC | newest]

Thread overview: 99+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-30 18:25 [TUHS] A few comments on porting the Bourne shell Paul Ruizendaal
2022-12-30 19:51 ` [TUHS] " Chet Ramey
2022-12-30 20:02   ` Larry McVoy
2022-12-30 20:31     ` Adam Thornton
2022-12-30 20:49       ` Chet Ramey
2022-12-30 20:42     ` Sven Mascheck
2022-12-30 20:48       ` Jon Steinhart
2022-12-30 20:51         ` Sven Mascheck
2022-12-31 11:40         ` Ralph Corderoy
2022-12-31 18:49           ` Jon Steinhart
2022-12-31 19:24             ` Clem Cole
2023-01-03 16:32               ` Chet Ramey
2023-01-01  1:51             ` Ron Natalie
2023-01-02 20:03       ` [TUHS] Command Line Editing in the Terminal Driver (Was: A few comments on porting the Bourne shell) Joseph Holsten
2023-01-02 20:33         ` [TUHS] Re: Command Line Editing in the Terminal Driver Lars Brinkhoff
2023-01-11  2:51           ` Chris Hanson
2023-01-11  3:53             ` Greg 'groggy' Lehey
2023-01-02 21:08         ` [TUHS] Re: Command Line Editing in the Terminal Driver (Was: A few comments on porting the Bourne shell) Rob Pike
2023-01-03 16:53         ` Marshall Conover
2023-01-04  9:18           ` Joseph Holsten
2023-01-11  2:56           ` Chris Hanson
2022-12-30 20:47     ` [TUHS] Re: A few comments on porting the Bourne shell Chet Ramey
2022-12-31  0:08     ` Luther Johnson
2022-12-31  3:59       ` Larry McVoy
2022-12-31  4:12         ` Steve Nickolas
2022-12-31  4:18         ` Bakul Shah
2022-12-31  4:40           ` Larry McVoy
2022-12-31  4:19         ` Marc Donner
2022-12-31  4:23         ` Dave Horsfall
2022-12-31  4:37           ` Clem Cole
2023-01-02  5:10           ` Mary Ann Horton
2023-01-02 16:25             ` Clem Cole
2023-01-02 16:51               ` Larry McVoy
2023-01-02 17:32                 ` Adam Thornton
2023-01-02 17:43                   ` Larry McVoy
2023-01-02 17:48                     ` Luther Johnson
2023-01-02 18:00                       ` G. Branden Robinson
2023-01-02 18:05                         ` Luther Johnson
2023-01-02 18:12                         ` Larry McVoy
2023-01-02 18:16                           ` Clem Cole
2023-01-02 19:50                             ` Warner Losh
2023-01-02 20:05                               ` Adam Thornton
2023-01-02 19:21                           ` G. Branden Robinson
2023-01-02 19:34                             ` Rich Salz
2023-01-02 20:12                               ` Larry McVoy
2023-01-02 20:24                               ` G. Branden Robinson
2023-01-02 20:41                                 ` Larry McVoy
2023-01-02 21:00                                   ` Dan Cross
2023-01-02 21:06                                     ` Clem Cole
2023-01-02 21:19                                       ` Dan Cross
2023-01-02 22:54                                         ` segaloco via TUHS
2023-01-02 23:58                                           ` Jon Steinhart
2023-01-04  9:00                                             ` Joseph Holsten
2023-01-02 22:43                                       ` Steve Nickolas
2023-01-02 21:08                                     ` Joseph Holsten
2023-01-02 21:15                                       ` Adam Thornton
2023-01-02 17:55                     ` Adam Thornton
2023-01-02 18:11                       ` Clem Cole
2023-01-02 18:36                         ` Dan Cross
2023-01-02 18:48                           ` Dan Cross
2023-01-02 18:18                       ` Larry McVoy
2023-01-04  3:20                     ` John Cowan
2023-01-04  3:31                       ` Dan Cross
2023-01-04  4:16                         ` Bakul Shah
2023-01-04 16:15                           ` Dan Cross
2023-01-04 18:28                             ` ron minnich
2023-01-04 19:33                             ` Chet Ramey
2023-01-04 15:21                       ` Ralph Corderoy
2023-01-04 15:54                         ` Ron Natalie
2023-01-02 17:55                 ` Clem Cole
2023-01-03 17:08                   ` Paul Winalski
2023-01-03 19:19                     ` Warner Losh
2023-01-03 19:56                       ` Luther Johnson
2023-01-03 20:21                       ` Dave Horsfall
2023-01-03 21:47                       ` Clem Cole
2023-01-03 21:51                         ` Clem Cole
2022-12-31  4:41         ` Greg 'groggy' Lehey
2022-12-30 20:20   ` Sven Mascheck
2022-12-30 20:49     ` Ron Natalie
2022-12-30 20:52       ` Rob Pike
2022-12-30 20:53       ` Jon Steinhart
2023-01-01 10:44   ` arnold
2023-01-01 11:28     ` arnold
2023-01-03 16:34       ` Chet Ramey
2023-01-03 15:06     ` Chet Ramey
2022-12-30 19:57 ` segaloco via TUHS
2022-12-31 12:55   ` Paul Ruizendaal
2023-01-01  2:55     ` Warner Losh
2023-01-01  4:38       ` Jonathan Gray
2023-01-01  5:25         ` Warner Losh
2023-01-01  5:35           ` Dan Cross
2023-01-01  5:52             ` G. Branden Robinson
2023-01-01  6:35               ` Warner Losh
2023-01-01  6:35               ` Rob Pike
2023-01-01  6:27             ` Warner Losh
2023-01-01 14:50             ` Ron Natalie
2023-01-01  7:11           ` Jonathan Gray
2023-01-01  7:21             ` Warner Losh
2023-01-01 10:25           ` Paul Ruizendaal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).