From ad14dee7f2f3f85faf91df266df946c3de597e51 Mon Sep 17 00:00:00 2001 From: NicJA Date: Wed, 31 Dec 2014 01:43:52 +0000 Subject: [PATCH] If MEMF_REVERSE is specified, it is documented the memlist should be traversed in reverse - not just the chunks in a memheader. Respect that behaviour, since there may be more regions that match the requested allocation other than the first encountered. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@49878 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- rom/exec/memory_nommu.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/rom/exec/memory_nommu.c b/rom/exec/memory_nommu.c index 8a0f8c4476..3fcdc0261c 100644 --- a/rom/exec/memory_nommu.c +++ b/rom/exec/memory_nommu.c @@ -22,15 +22,27 @@ APTR nommu_AllocMem(IPTR byteSize, ULONG flags, struct TraceLocation *loc, struct ExecBase *SysBase) { APTR res = NULL; - struct MemHeader *mh; + struct MemHeader *mh, *mhn; ULONG requirements = flags & MEMF_PHYSICAL_MASK; /* Protect memory list against other tasks */ MEM_LOCK; + if (flags & MEMF_REVERSE) + mhn = GetTail(&SysBase->MemList); + else + mhn = GetHead(&SysBase->MemList); + /* Loop over MemHeader structures */ - ForeachNode(&SysBase->MemList, mh) + while (mhn) { + mh = mhn; + + if (flags & MEMF_REVERSE) + mhn = (((struct Node *)(mh))->ln_Pred); + else + mhn = (((struct Node *)(mh))->ln_Succ); + /* * Check for the right requirements and enough free memory. * The requirements are OK if there's no bit in the -- 2.11.4.GIT