Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!fuug!news.funet.fi!ra!rosenber From: rosenber@ra.abo.fi (Robin Rosenberg INF) Newsgroups: comp.sys.amiga.programmer Subject: Re: Help! (AmigaDOS CreateProc/LoadSeg) Message-ID: Date: 11 Mar 91 17:30:29 GMT References: <63329@eerie.acsu.Buffalo.EDU> <19578@cbmvax.commodore.com> <06417.AA06417@babylon.rmt.sub.org> Sender: rosenber@ra.abo.fi Organization: Abo Akademi University, Finland Lines: 48 In-reply-to: rbabel@babylon.rmt.sub.org's message of 6 Mar 91 11:58:01 GMT 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. struct FakeSeg { LONG size; BPTR next; LONG move_inst; WORD jump_inst; APTR codeptr; }; static struct FakeSeg __far FS = { 0,0, 0x207A0004, /* MOVEA.L 4(PC),A0 */ 0x4ED0, /* JMP (A0) */ 0 /* *DATA*, not code */ }; struct MsgPort *QuickCreateProc(UBYTE name,LONG pri,APTR func,LONG stacksize) { /* Now I modify the faked segment, no not the code, only the data */ FS.codeptr = func; return CreateProc(name,pri, (ULONG)&FS.next >> 2 ,stacksize); } Have fun Robin