/* ** $VER: CatchFrags.c 1.1 (18.10.99) by Bernardo Innocenti ** ** Try to catch who's fragmenting the memory list with small allocations ** ** TODO: Rewrite patches in ASM so it will be possible to ** print out the return address (to be passed to SegTracker). */ #include #include #include #include #include #include "CompilerSpecific.h" /* Prototypes */ STDARGS extern void kprintf (const char *, ...); APTR ASMCALL NewAllocMem ( REG(d0, unsigned long byteSize), REG(d1, unsigned long requirements), REG(a6, struct ExecBase *SysBase)); void ASMCALL NewFreeMem ( REG(a1, APTR memoryBlock), REG(d0, unsigned long byteSize), REG(a6, struct ExecBase *SysBase)); /* Typedefs */ typedef APTR ASMCALL (*AllocMem_t) ( REG(d0, unsigned long byteSize), REG(d1, unsigned long requirements), REG(a6, struct ExecBase *SysBase)); typedef void ASMCALL (*FreeMem_t) ( REG(a1, APTR memoryBlock), REG(d0, unsigned long byteSize), REG(a6, struct ExecBase *SysBase)); /* Global variables */ AllocMem_t OldAllocMem; FreeMem_t OldFreeMem; LONG _main (void) { struct ExecBase *SysBase = *((struct ExecBase **) 4); Forbid(); OldAllocMem = (AllocMem_t)SetFunction((struct Library *)SysBase, -0xc6, (ULONG (*)())NewAllocMem); OldFreeMem = (FreeMem_t)SetFunction((struct Library *)SysBase, -0xd2, (ULONG (*)())NewFreeMem); CacheClearU(); Permit(); Wait(SIGBREAKF_CTRL_C); Forbid(); SetFunction((struct Library *)SysBase, -0xd2, (ULONG (*)())OldFreeMem); SetFunction((struct Library *)SysBase, -0xc6, (ULONG (*)())OldAllocMem); CacheClearU(); Permit(); return 0; } APTR ASMCALL NewAllocMem ( REG(d0, unsigned long byteSize), REG(d1, unsigned long requirements), REG(a6, struct ExecBase *SysBase)) { APTR block = OldAllocMem(byteSize, requirements, SysBase); if (byteSize <= 8) kprintf("AllocMem() %ld bytes at 0x%08lx by 0x%08lx\n", byteSize, block, SysBase->ThisTask); return block; } void ASMCALL NewFreeMem ( REG(a1, APTR memoryBlock), REG(d0, unsigned long byteSize), REG(a6, struct ExecBase *SysBase)) { if (byteSize <= 8) kprintf("FreeMem() %ld bytes at 0x%08lx by 0x%08lx\n", byteSize, memoryBlock, SysBase->ThisTask); OldFreeMem(memoryBlock, byteSize, SysBase); } static const char version[] = "$VER: CatchFrags 1.1 (18.10.99) by Bernardo Innocenti";