Path: utzoo!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!uunet!ogicse!pdxgate!eecs!bairds From: bairds@eecs.cs.pdx.edu (Shawn L. Baird) Newsgroups: comp.sys.amiga.programmer Subject: Re: Problem with SetFunction() Keywords: AllocMem() SetPatch() 2.02 Message-ID: <1995@pdxgate.UUCP> Date: 18 Mar 91 07:49:31 GMT Article-I.D.: pdxgate.1995 References: <13531@darkstar.ucsc.edu> Sender: news@pdxgate.UUCP Lines: 60 davids@ucscf.UCSC.EDU (Dave Schreiber) writes: >I've been trying to patch AllocMem() as an experiment, and haven't been >able to get it to work. I manage to patch it correctly with SetFunction(), >but when I try to print a carriage return using printf, the machine crashes >with a 8000 0006 error (CHK instruction). Here's the code: [ stuff deleted ] > Forbid(); /*Stop multitasking*/ > /*Patch AllocMem()*/ > oldAllocMem=SetFunction(ExecBase,NEG_AM_OFFSET,newAllocMem); > temp=(APTR)AllocMem(1000,0L); /*Goes to my routine & allocates*/ > /*the memory without a problem*/ > printf("%x ",temp); /*Crashes here if there's a \n in that line*/ > /*Otherwise, it just continues on fine*/ > /*Undo patch*/ > printf("%x\n",SetFunction(ExecBase,NEG_AM_OFFSET,oldAllocMem)); > Permit(); [ more stuff deleted ] Here's my $0.02. Since you've stopped multi-tasking the console device, which is another task, cannot run. Thus the crash. Since stdout doesn't flush until it gets a newline... Try this instead: Forbid(); /*Stop multitasking*/ /*Patch AllocMem()*/ oldAllocMem=SetFunction(ExecBase,NEG_AM_OFFSET,newAllocMem); Permit(); temp=(APTR)AllocMem(1000,0L); /*Goes to my routine & allocates*/ /*the memory without a problem*/ printf("%x\n",temp); /*Crashes here if there's a \n in that line*/ /*Otherwise, it just continues on fine*/ Forbid(); /*Undo patch*/ tmpfunc=SetFunction(ExecBase,NEG_AM_OFFSET,oldAllocMem)); Permit(); printf("%x\n",tmpfunc); /* print out the address of the old routine */ /* if tmpfunc != newAllocMem then somebody else probably also did a SetFunction() while we were running I guess */ | Shawn L. Baird | Or via US Snail: | | bairds@eecs.ee.pdx.edu | 17650 SE Cason Rd. | | ...uunet!tektronix!psueea!eecs!bairds | Gladstone, OR 97027 |