From a8c5966ab27c7e487eae563550bef0013f8d9a63 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Mon, 10 Jul 2023 06:12:43 -0700 Subject: [PATCH] Elaborate on 2001/anonymous fix in thanks file Mostly for educational value and because I documented a fair bit but it was incomplete and I don't like to be incomplete. --- thanks-for-fixes.md | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 4ca714d2b..42c76b2ac 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -80,6 +80,11 @@ so that everyone can enjoy it with systems that are not VAX/PDP. We also refer y to the [FAQ](faq.md) as there are some winning entries that also let one enjoy it - with more to them of course! +Cody also added the [gentab.c](1984/mullender/gentab.c) file, modified to +compile with modern systems, which the author noted in their remarks which Cody +also found. + + ## [1985/applin](1985/applin/applin.c) ([README.md](1985/applin/README.md])) Yusuke provided a patch to get this to not crash and Cody fixed this to @@ -825,16 +830,40 @@ but according to the author's remarks it should be executed). He managed to do this with linux but it will not work with macOS (see [bugs.md](/bugs.md) for why this is); _this is **not** a bug, it's a feature_ inherent in what it does! -The following had to be done in order to get this to work: +Below is what it took to fix. - `#include ` for `mmap()` and `munmap()`. - have `main()` call another function which is no longer a recursive function; this prevented `main()` from entering an infinite recursive loop. -Without either of these it would crash and prevent modification of the 32-bit +Without these it would crash and prevent modification of the 32-bit [ELF](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format) (not elf :-) ) binary. But again see [bugs.md](/bugs.md) here. +These also had to be done: + +- when `open()`ing the file the file descriptor had to be saved so it could be +closed prior to executing the program. +- `munmap()` also had to be called prior to executing the program. + +Without those changes the program was not executed after modification which it +was supposed to do, instead reporting text file busy error. + +Notice that the location of the calls to `munmap()` and `close()` followed by +`execv()` _does matter_! + +To get this to compile with clang, `main()` had to change from: + +```c +main (char *ck, char **k) +``` + +to: + +```c +int main (int cka, char **k) { char *ck = (char *)cka; /* ... */ } +``` + The following change was also made to be more portable, in case the constants `PROT_READ` and/or `PROT_WRITE` are not standardised: @@ -842,17 +871,6 @@ Change `3` in the call to `mmap()` to be `PROT_READ|PROT_WRITE`: just in case `PROT_READ|PROT_WRITE` does not equal 3 (though it seems to be equal in both macOS and linux). -There was one other thing that had to be done though. Since the program used to -recursively call (infinite recursion, seemingly) `main()` and since that cannot -be done what had to be done instead is after the new function (`pain()` since it -was a pain to fix :-) ) returns to first call `munmap()` and `close()` (else one -would get text file busy error) and then the program can call `execv()` again -like the function `pain()` (was in `main()`) did but with a slight change. See -commit `2159caec4677e0f25ad704a74e04c8196fd6c343` for more details. - -Notice that the location of the calls to `munmap()` and `close()` followed by -`execv()` _does matter_! - NOTE: there might be educational value to see the progress of this fix; if you wish to see, try the following commands from the `2001/anonymous` directory: