Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!agate!darkstar!ucscf.UCSC.EDU!davids From: davids@ucscf.UCSC.EDU (Dave Schreiber) Newsgroups: comp.sys.amiga.programmer Subject: Problem with SetFunction() Keywords: AllocMem() SetPatch() 2.02 Message-ID: <13531@darkstar.ucsc.edu> Date: 18 Mar 91 03:45:31 GMT Sender: usenet@darkstar.ucsc.edu Organization: University of California, Santa Cruz Lines: 64 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: #include #include #include struct ExecBase *ExecBase; APTR __regargs (*oldAllocMem)(); APTR __regargs newAllocMem(ULONG size,ULONG types); #define NEG_AM_OFFSET 0xff3a main() { APTR temp; ExecBase=(struct ExecBase *)OpenLibrary("exec.library",0L); 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(); if(temp!=0L) FreeMem(temp,1000); /*Again, doesn't crash*/ CloseLibrary(ExecBase); /*Exits without a hitch*/ } APTR __regargs newAllocMem(ULONG size,ULONG types) { return(oldAllocMem(size,types)); } If I change newAllocMem() so that it just returns NULL, the call to AllocMem() in main() returns NULL; i.e. I know that calls to AllocMem() are being routed to my module. newAllocMem() as it is above also works without a hitch. But when I printf() an '\n' (or when I Permit() without undoing the patch), it crashes. Any suggestions? BTW, I'm using a 3000 under 2.02 (under 1.3 it crashes as well, but it gives a 8000 0003 error). Thanks in advance. -- Dave Schreiber E-mail: davids@ucscf.ucsc.edu "It was fun learning about logic, but I don't see where or when I will ever use it again." Disclaimer: