Xref: utzoo comp.lang.c:11317 comp.arch:5475 Path: utzoo!utgpu!water!watmath!clyde!att!pacbell!ames!ubvax!vsi1!altnet!uunet!seismo!esosun!jackson From: jackson@esosun.UUCP (Jerry Jackson) Newsgroups: comp.lang.c,comp.arch Subject: Re: Self-modifying code Message-ID: <227@esosun.UUCP> Date: 14 Jul 88 19:20:33 GMT References: <3353@cognos.UUCP> <619@goofy.megatest.UUCP> <429@uwovax.uwo.ca> <5254@june.cs.washington.edu> <12357@ut-sally.UUCP> <5262@june.cs.washington.edu> <752@cernvax.UUCP> Organization: SAIC, San Diego Lines: 55 In-reply-to: hjm@cernvax.UUCP's message of 13 Jul 88 09:44:20 GMT In article <752@cernvax.UUCP> hjm@cernvax.UUCP (hjm) writes: Path: esosun!seismo!uunet!mcvax!cernvax!hjm From: hjm@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@cognos.UUCP> <619@goofy.megatest.UUCP> <429@uwovax.uwo.ca> <5254@june.cs.washington.edu> <12357@ut-sally.UUCP> <5262@june.cs.washington.edu> Reply-To: hjm@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@seismo.css.gov | | SAIC SOUND: (619)458-4924 | | 10210 Campus Point Drive | | San Diego, CA 92121 | +-----------------------------------------------------------------------------+