Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!rutgers!cbmvax!cbmehq!babylon!rbabel From: rbabel@babylon.rmt.sub.org (Ralph Babel) Newsgroups: comp.sys.amiga.programmer Subject: Re: Starting another copy of your own code (was Re: Help! (AmigaDOS CreateProc/LoadSeg) Message-ID: <06493.AA06493@babylon.rmt.sub.org> Date: 9 Mar 91 13:01:35 GMT References: <63329@eerie.acsu.Buffalo.EDU> <19578@cbmvax.commodore.com> <06417.AA06417@babylon.rmt.sub.org> <18cb4d63.ARN0b56@swinjm.UUCP> <1991Mar9.170859.4810@Sandelman.OCUnix.On.Ca> Reply-To: cbmvax.commodore.com!cbmehq!babylon!rbabel (Ralph Babel) Lines: 68 In article <18cb4d63.ARN0b56@swinjm.UUCP>, forgeas@swinjm.UUCP (Jean-Michel Forgeas) writes: > I don't see where you find self-modifying code in the > example above. All I see is data (while there is no > process running on it). Effectively after CreateProc() on ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > it this data becomes code, but there is no modification of ^^^^^^^^^^^^^^^^^^^^^^^^^ > the code after CreateProc(). This is not true! It's always the function that brings the code into memory (e.g. LoadSeg()) that is supposed to keep the code cache up to date, not the function to execute this code (e.g. CreateProc()). The same code might be executed several times (even concurrently), so clearing the cache every time would be wasteful. These are the only legal ways of bringing code into memory: - ROM-code - DAC_WORDWIDE - DAC_BYTEWIDE - DAC_NIBBLEWIDE - MakeFunctions() - MakeLibrary() - SetFunction() - LoadSeg() Putting an entry into the Captures/KickTags and rebooting the system _might_ also be considered safe. 2.0 provides a few additional functions (e.g. InternalLoadSeg()) plus some cache control calls. In article <1991Mar9.170859.4810@Sandelman.OCUnix.On.Ca>, mcr@Sandelman.OCUnix.On.Ca (Michael Richardson) writes: > Please suggest an alternative to doing this. Simply use a function entry that is longword-aligned, e.g. an assembly language stub after a "CNOP 0,4" or the first (C-) function in an object module, and convert it to a seglist: void (*pfv)(void); BPTR sl; sl = (BPTR)(((ULONG)pfv >> 2) - 1); > So far code like this [PhonySegList] (Hmm. I don't have a > SegSize at the beginning though) has been working on > A3000s for some time now. 256 bytes of cache isn't a lot. It even works under 1.3. > Is there now a 2.0 function for doing the same thing? 2.0 dos.library allows one to specify a regular function address instead of a (longword-aligned) seglist. > /* From Leoproc.zoo. By Leo Schwab. */ > > CopyMem(&template, fakelist, sizeof(struct PhonySegList)); > fakelist->psl_EntryPoint = SlaveStart; Sorry, self-modifying code. Even if Leo did it. :-) Ralph