Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!dkuug!diku!bombadil From: bombadil@diku.dk (Kristian Nielsen) Newsgroups: comp.sys.amiga.programmer Subject: Re: Help! (AmigaDOS CreateProc/LoadSeg) Message-ID: <1991Mar12.123403.2415@odin.diku.dk> Date: 12 Mar 91 12:34:03 GMT References: <63329@eerie.acsu.Buffalo.EDU> <19578@cbmvax.commodore.com> <06417.AA06417@babylon.rmt.sub.org> Sender: news@odin.diku.dk (Netnews System) Organization: Department of Computer Science, U of Copenhagen Lines: 54 rosenber@ra.abo.fi (Robin Rosenberg INF) writes: >In article <06417.AA06417@babylon.rmt.sub.org> rbabel@babylon.rmt.sub.org (Ralph Babel) writes: >>In article <19578@cbmvax.commodore.com>, >>ken@cbmvax.commodore.com (Ken Farinsky - CATS) writes: >>> LoadSeg() needs a BPTR to a seg list, which can be faked >>> like: >>> >>> /* From Mike Sinz AmigaMail example */ >>> struct CodeHdr >>> { >>> ULONG SegSize; /* sizeof(struct CodeHdr) */ >>> ULONG NextSeg; /* Must be NULL */ >>> UWORD JumpInstr; /* set to 0x4EF9 (a jump instruction) */ >>> APTR Function; /* a pointer to the function */ >>> } >>I'd call this self-modifying code. >>Ralph >I have a slightly different version, that does not contain >self-modifying code. Instead of patching the jump instrction, I patch >data for the instruction. This code is of course not reentrant. Why go to all this trouble? Just use the AmigaMail example like this: void foo(void){ DoSomeThing(); } /* Static initialised data (really code). */ struct CodeHdr fooSegList={ sizeof(struct CodeHdr), NULL, 0x4EF9, (APTR)foo }; void main(void){ CreateProc(&CodeHdr>>2,...); } Since the struct CodeHdr is initialised at compiletime, this is not using self-modifying code; the code never changes after the original LoadSeg() (if LoadSeg differentiates between CODE and DATA sections, it might be nessesary to ensure that the structure is placed in the CODE section; I'm not really sure about this point). Also, it is fully reentrant (provided that one keeps a seperate structure for each function and that one does not change it, of course). Kristian.