02 December 2016

Horrible Hacks

A confession inspired by this article... here's one of my horrible hacks.

I once ran out of space for buffers in a program on the PDP-11, so I re-used some of the stack space above main()s entry for extra scratch space, and then made sure main() never returned. There was a bunch of memory (over a kilobyte!) at the top of stack containing the environment and command line arguments, so that was space I didn't need once I started. So long as I scanned them and stashed anything of value before I needed to use the space, anyway.

But later it turned out I needed the environment back when I wanted to run another program so the first thing I did was write() the environment to a file, and then when I called anything I read() that file back into place between the fork() and exec().
So, what horrible hacks are you guiltily proud of?

No comments:

Post a Comment