Self-modifying code

Jerry Jackson jackson at esosun.UUCP
Fri Jul 15 05:20:33 AEST 1988


In article <752 at cernvax.UUCP> hjm at cernvax.UUCP (hjm) writes:

   Path: esosun!seismo!uunet!mcvax!cernvax!hjm
   From: hjm at cernvax.UUCP (hjm)
   Newsgroups: comp.lang.c,comp.arch
   Summary: What is self-modifying code anyway?
   Keywords: self-modifying code
   Date: 13 Jul 88 09:44:20 GMT
   References: <3353 at cognos.UUCP> <619 at goofy.megatest.UUCP> <429 at uwovax.uwo.ca> <5254 at june.cs.washington.edu> <12357 at ut-sally.UUCP> <5262 at june.cs.washington.edu>
   Reply-To: hjm at cernvax.UUCP ()
   Organization: CERN European Laboratory for Particle Physics, CH-1211 Geneva, Switzerland
   Lines: 36
   Xref: esosun comp.lang.c:11534 comp.arch:5582

>>   As a final note, why is it 'clean' to alter a jump table and 'unclean' to alter
>>   an inline constant (e.g. jmp @offset(r0) uses a value in memory as the address
>>   but mov (pc)+,#1234 which loads an immediate does so too)?  Why the subtle
>>   difference?  Any thoughts on the subject?

	   Hubert Matthews

   (I don't consider LISP or PROLOG programs that create code on the fly to be
   SMC.  Does anyone disagree?)


The main difference that I see is that the code in one case is not
reentrant.  In systems like unix where it is possible for more than
one process to share a code segment at runtime, the jump table is
local to each process while the code is not.  Imagine if vi had true
self-modifying code in it...  (Many users typically share a code
segment for programs like vi and csh) The example in which you create
an array and then call it as a function does not really fit this
definition of self-modifying, since the code that is changed is
created in data space at runtime and hence cannot interfere with other
programs using the same code segment.

*Real* SMC would be something like:

main()
{
	char func();
	long *longptr;

	longptr = (long *)func;
	*(longptr + 20) = 0xffffffff;  /* shudder!!!!! */
}

+-----------------------------------------------------------------------------+
|   Jerry Jackson                       UUCP:  seismo!esosun!jackson          |
|   Geophysics Division, MS/22          ARPA:  esosun!jackson at seismo.css.gov  |
|   SAIC                                SOUND: (619)458-4924                  |
|   10210 Campus Point Drive                                                  |
|   San Diego, CA  92121                                                      |
+-----------------------------------------------------------------------------+



More information about the Comp.lang.c mailing list