Merge pull request #909 from xexyl/2001-anonymous-thanks
This commit is contained in:
1 file changed
+31
-13
+31
-13
@@ -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
|
to the [FAQ](faq.md) as there are some winning entries that also let one enjoy
|
||||||
it - with more to them of course!
|
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]))
|
## [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
|
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 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!
|
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 <sys/mman.h>` for `mmap()` and `munmap()`.
|
- `#include <sys/mman.h>` for `mmap()` and `munmap()`.
|
||||||
- have `main()` call another function which is no longer a recursive function;
|
- have `main()` call another function which is no longer a recursive function;
|
||||||
this prevented `main()` from entering an infinite recursive loop.
|
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 :-) )
|
[ELF](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format) (not elf :-) )
|
||||||
binary. But again see [bugs.md](/bugs.md) here.
|
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
|
The following change was also made to be more portable, in case the constants
|
||||||
`PROT_READ` and/or `PROT_WRITE` are not standardised:
|
`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
|
`PROT_READ|PROT_WRITE` does not equal 3 (though it seems to be equal in both
|
||||||
macOS and linux).
|
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
|
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:
|
wish to see, try the following commands from the `2001/anonymous` directory:
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user