From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 25482 invoked from network); 30 Dec 2022 18:27:26 -0000 Received: from minnie.tuhs.org (50.116.15.146) by inbox.vuxu.org with ESMTPUTF8; 30 Dec 2022 18:27:26 -0000 Received: from minnie.tuhs.org (localhost [IPv6:::1]) by minnie.tuhs.org (Postfix) with ESMTP id 0A28F4237A; Sat, 31 Dec 2022 04:26:17 +1000 (AEST) Received: from ewsoutbound.kpnmail.nl (unknown [195.121.94.169]) by minnie.tuhs.org (Postfix) with ESMTPS id ED2764237A for ; Sat, 31 Dec 2022 04:26:07 +1000 (AEST) X-KPN-MessageId: 66124191-886f-11ed-97dd-005056abad63 Received: from smtp.kpnmail.nl (unknown [10.31.155.40]) by ewsoutbound.so.kpn.org (Halon) with ESMTPS id 66124191-886f-11ed-97dd-005056abad63; Fri, 30 Dec 2022 19:25:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=planet.nl; s=planet01; h=to:date:message-id:subject:mime-version:content-type:from; bh=tCZBeVm36s9WDC9paKpvAKfTQdxkk3ExZuXzt4mDqBE=; b=YnZuDX8lxmlvjgBsmd1sJs881sz6Neak5ZSpt7oCqMFjXsbRlewd+eQvHCqTuedVtEVRZJwWdE6F3 D1/gtYvBIFYMQf0XmtkJ3imjJuv3jiCO0bGnnp/VyAy9G7K5dVemBNPrcVeVnyT//KsvjBKKnzVx55 quHQJK67g/TjviCU= X-KPN-MID: 33|/MakaAtsokW8K1h9s4c2BtO2RzoJSV9Bmc4YaCEyeU+9vu+XH7ck+kUCyctlsqn E8iygFLMH6/P7UIQkQiqKYg== X-KPN-VerifiedSender: Yes X-CMASSUN: 33|0P53s6vE+XpaC15FDEIsT1WOOlCcnADQ1Pra8Ye5wE+dvkZrH6fDa4OWpAUXUC9 MMWuEGrUCMAUDvnUcRaMoKQ== X-Originating-IP: 77.172.38.96 Received: from smtpclient.apple (77-172-38-96.fixed.kpn.net [77.172.38.96]) by smtp.kpnmail.nl (Halon) with ESMTPSA id 6689ae08-886f-11ed-927c-005056ab7584; Fri, 30 Dec 2022 19:25:56 +0100 (CET) From: Paul Ruizendaal Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Message-Id: <52FB6638-AEFF-4A4F-8C2E-32089D577BA0@planet.nl> Date: Fri, 30 Dec 2022 19:25:55 +0100 To: The Eunuchs Hysterical Society X-Mailer: Apple Mail (2.3654.120.0.1.13) Message-ID-Hash: HAB6ENCTUF32X6PDD45XGSETFIB56KRW X-Message-ID-Hash: HAB6ENCTUF32X6PDD45XGSETFIB56KRW X-MailFrom: pnr@planet.nl X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-tuhs.tuhs.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [TUHS] A few comments on porting the Bourne shell List-Id: The Unix Heritage Society mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: London and Reiser report about porting the shell that =E2=80=9Cit = required by far the largest conversion effort of any supposedly portable = program, for the simple reason that it is not portable.=E2=80=9D 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: /* 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)) 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=E2=80=99d = 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: rename(f1,f2) REG INT f1, f2; { #ifdef RES /* research has different sys calls from TS = */ IF f1!=3Df2 THEN dup(f1|DUPFLG, f2); close(f1); IF f2=3D=3D0 THEN ioset|=3D1 FI FI #else INT fs; IF f1!=3Df2 THEN fs =3D fcntl(f2,1,0); close(f2); fcntl(f1,0,f2); close(f1); IF fs=3D=3D1 THEN fcntl(f2,2,1) FI IF f2=3D=3D0 THEN ioset|=3D1 FI FI #endif } I=E2=80=99ve 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. = =46rom 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: VOID fault(sig) REG INT sig; { signal(sig, fault); IF sig=3D=3DMEMF THEN IF setbrk(brkincr) =3D=3D -1 THEN error(nospace); FI ELIF ... 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.