Swap usage discussion

Ed Skinner plug-devel@lists.PLUG.phoenix.az.us
Fri Jun 18 22:12:02 2004


On Friday 18 June 2004 21:13, Ted Gould wrote:
> On Fri, 2004-06-18 at 09:21, Ed Skinner wrote:
> > * Code pages can be "dropped" and not swapped out, just abandoned,
> > because the content is unchanged and, if needed, Linux can simply go back
> > to the executable file to reload any needed pages.
>
> So does that mean that self-modifying code is supported in Linux?
> That's interesting - typically considered a bad thing, but I guess there
> are probably some programs that use that for something.

The code "segment" is write-protected so self-modifying code, at least in 
normal practice, is not possible. Here's a brief attempt that fails. It 
suffers a "segment fault" before the second printf.


#include <stdio.h>

int main()
{
	int	* ptr;

	printf("I'm going to attempt to modify my own code now!\n");
	ptr = (int *) main;
	*ptr = 0;
	printf("I'm still alive!\n");
	exit(0);
}


-- 
Ed Skinner, ed@flat5.net, http://www.flat5.net/