Skip to content

Commit 726faac

Browse files
committed
exec: free-list, allocator, task and memory bugfixes
- switch HANDLE_MANAGED_MEM tests from #ifdef to #if (the macro is defined as 0 when disabled, so #ifdef was wrong) - memory: free-list consistency, MEMF_MANAGED tests, pool fixes - memory_nommu: round byteSize up to MEMCHUNK_TOTAL in AllocMem - newaddtask: pass MemEntry list head correctly - prepareexecbase: respect "nomungwall" arg, OR-in stacksnoop flag instead of clobbering, fix Preparation debug print - remtask: Disable around list removal to protect against interrupt-level Signal moving the task between lists - signal: priority comparison uses strict greater-than for preemption; corrected debug-print arguments
1 parent 9cdd24f commit 726faac

14 files changed

Lines changed: 52 additions & 38 deletions

rom/exec/allocate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
{
8585
AROS_LIBFUNC_INIT
8686

87-
#ifdef HANDLE_MANAGED_MEM
87+
#if HANDLE_MANAGED_MEM
8888
if ((freeList->mh_Node.ln_Type == NT_MEMORY) && IsManagedMem(freeList))
8989
{
9090
struct MemHeaderExt *mhe = (struct MemHeaderExt *)freeList;

rom/exec/allocpooled.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
if(!memSize)
7676
return NULL;
7777

78-
#ifdef HANDLE_MANAGED_MEM
78+
#if HANDLE_MANAGED_MEM
7979
if (IsManagedMem(mhe))
8080
{
8181
ULONG poolrequirements = (ULONG)(IPTR)mhe->mhe_MemHeader.mh_First;

rom/exec/allocvecpooled.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
/* 0-sized allocation results in returning NULL (API guarantee) */
5757
if(!memSize)
5858
return NULL;
59-
#ifdef HANDLE_MANAGED_MEM
59+
#if HANDLE_MANAGED_MEM
6060
if (IsManagedMem(mhe))
6161
{
6262
ULONG poolrequirements = (ULONG)(IPTR)mhe->mhe_MemHeader.mh_First;

rom/exec/createpool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
* If the pool is in managed memory, don't bother any further setup. The
140140
* pool should do the rest self.
141141
*/
142-
#ifdef HANDLE_MANAGED_MEM
142+
#if HANDLE_MANAGED_MEM
143143
if (IsManagedMem(firstPuddle))
144144
{
145145
D(bug("Managed pool\n");)

rom/exec/deallocate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
{
5959
AROS_LIBFUNC_INIT
6060

61-
#ifdef HANDLE_MANAGED_MEM
61+
#if HANDLE_MANAGED_MEM
6262
if ((freeList->mh_Node.ln_Type == NT_MEMORY) && IsManagedMem(freeList))
6363
{
6464
struct MemHeaderExt *mhe = (struct MemHeaderExt *)freeList;

rom/exec/deletepool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
{
6262
struct TraceLocation tp = CURRENT_LOCATION("DeletePool");
6363

64-
#ifdef HANDLE_MANAGED_MEM
64+
#if HANDLE_MANAGED_MEM
6565
if (IsManagedMem(poolHeader))
6666
{
6767
/* Do nothing, everything is handled in FreeMemHeader */

rom/exec/freepooled.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
if(!memSize || !memory)
6262
return;
6363

64-
#ifdef HANDLE_MANAGED_MEM
64+
#if HANDLE_MANAGED_MEM
6565
if (IsManagedMem(mhe))
6666
{
6767
if (mhe->mhe_Free)

rom/exec/freevecpooled.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
if(!memory)
5858
return;
5959

60-
#ifdef HANDLE_MANAGED_MEM
60+
#if HANDLE_MANAGED_MEM
6161
if (IsManagedMem(mhe))
6262
{
6363
if (mhe->mhe_FreeVec)

rom/exec/memory.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct MemHeader *FindMem(APTR address, struct ExecBase *SysBase)
3333

3434
while (mh->mh_Node.ln_Succ != NULL)
3535
{
36-
#ifdef HANDLE_MANAGED_MEM
36+
#if HANDLE_MANAGED_MEM
3737
if (IsManagedMem(mh))
3838
{
3939
struct MemHeaderExt *mhe = (struct MemHeaderExt *)mh;
@@ -376,7 +376,8 @@ void mhac_PoolMemHeaderSetup(struct MemHeader * mh, struct ProtectedPool * pool)
376376
#define mhac_PoolMemHeaderGetCtx(a) ((struct MemHeaderAllocatorCtx *)(a->mh_Node.ln_Name))
377377
#define mhac_PoolMemHeaderGetPool(a) (mhac_PoolMemHeaderGetCtx(a)->mhac_Data1)
378378

379-
#endif
379+
#endif // defined(NO_ALLOCATOR_CONTEXT)
380+
380381

381382

382383
#ifdef NO_CONSISTENCY_CHECKS
@@ -540,12 +541,8 @@ APTR stdAllocReverse(struct MemHeader *mh, struct MemHeaderAllocatorCtx *mhac, I
540541
struct MemChunk * pp = p1;
541542

542543
/* Return the last bytes. */
543-
p1->mc_Next=p2;
544544
mc = (struct MemChunk *)(MK_UBYTEPTR(p2)+p2->mc_Bytes-byteSize);
545-
546-
p1 = p1->mc_Next;
547-
p1->mc_Next = p2->mc_Next;
548-
p1->mc_Bytes = p2->mc_Bytes-byteSize;
545+
p2->mc_Bytes -= byteSize;
549546

550547
mhac_MemChunkCreated(p1, pp, mhac);
551548
}
@@ -556,7 +553,7 @@ APTR stdAllocReverse(struct MemHeader *mh, struct MemHeaderAllocatorCtx *mhac, I
556553
if (requirements & MEMF_CLEAR)
557554
memset(mc, 0, byteSize);
558555
}
559-
556+
#if !defined(NO_ALLOCATOR_CONTEXT)
560557
else
561558
{
562559
if (!mhac_IsIndexEmpty(mhac))
@@ -569,6 +566,7 @@ APTR stdAllocReverse(struct MemHeader *mh, struct MemHeaderAllocatorCtx *mhac, I
569566
mc = stdAlloc(mh, mhac, size, requirements, tp, SysBase);
570567
}
571568
}
569+
#endif
572570
return mc;
573571
}
574572

@@ -588,7 +586,7 @@ APTR stdAlloc(struct MemHeader *mh, struct MemHeaderAllocatorCtx *mhac, IPTR siz
588586
* The check has to be done for the second time. Exec uses stdAlloc on memheader
589587
* passed upon startup. This is bad, very bad. So here a temporary hack :)
590588
*/
591-
#ifdef HANDLE_MANAGED_MEM
589+
#if HANDLE_MANAGED_MEM
592590
if ((mh->mh_Node.ln_Type == NT_MEMORY) && IsManagedMem(mh))
593591
{
594592
struct MemHeaderExt *mhe = (struct MemHeaderExt *)mh;
@@ -654,7 +652,6 @@ APTR stdAlloc(struct MemHeader *mh, struct MemHeaderAllocatorCtx *mhac, IPTR siz
654652
/* Something found? */
655653
if (mc != NULL)
656654
{
657-
/* Remember: if MEMF_REVERSE is set p1 and p2 are now invalid. */
658655
p1 = mc;
659656
p2 = p1->mc_Next;
660657

@@ -688,6 +685,7 @@ APTR stdAlloc(struct MemHeader *mh, struct MemHeaderAllocatorCtx *mhac, IPTR siz
688685
if (requirements & MEMF_CLEAR)
689686
memset(mc, 0, byteSize);
690687
}
688+
#if !defined(NO_ALLOCATOR_CONTEXT)
691689
else
692690
{
693691
if (!mhac_IsIndexEmpty(mhac))
@@ -700,7 +698,8 @@ APTR stdAlloc(struct MemHeader *mh, struct MemHeaderAllocatorCtx *mhac, IPTR siz
700698
mc = stdAlloc(mh, mhac, size, requirements, tp, SysBase);
701699
}
702700
}
703-
return mc;
701+
#endif
702+
return mc;
704703
}
705704
}
706705

@@ -716,7 +715,7 @@ void stdDealloc(struct MemHeader *freeList, struct MemHeaderAllocatorCtx *mhac,
716715
struct MemChunk *p1, *p2, *p3;
717716
UBYTE *p4;
718717

719-
#ifdef HANDLE_MANAGED_MEM
718+
#if HANDLE_MANAGED_MEM
720719
if ((freeList->mh_Node.ln_Type == NT_MEMORY) && IsManagedMem(freeList))
721720
{
722721
struct MemHeaderExt *mhe = (struct MemHeaderExt *)freeList;
@@ -774,7 +773,7 @@ void stdDealloc(struct MemHeader *freeList, struct MemHeaderAllocatorCtx *mhac,
774773
/* Found a block with a higher address? */
775774
if (p2 >= p3)
776775
{
777-
#if !defined(NO_CONSISTENCY_CHECKS)
776+
// #if !defined(NO_CONSISTENCY_CHECKS)
778777
/*
779778
If the memory to be freed overlaps with the current
780779
block something must be wrong.
@@ -788,7 +787,7 @@ void stdDealloc(struct MemHeader *freeList, struct MemHeaderAllocatorCtx *mhac,
788787
Alert(AN_FreeTwice);
789788
return;
790789
}
791-
#endif
790+
// #endif
792791
/* End the loop with p2 non-zero */
793792
break;
794793
}
@@ -889,7 +888,7 @@ APTR AllocMemHeader(IPTR size, ULONG flags, struct TraceLocation *loc, struct Ex
889888
{
890889
struct MemHeader *orig = FindMem(mh, SysBase);
891890

892-
#ifdef HANDLE_MANAGED_MEM
891+
#if HANDLE_MANAGED_MEM
893892
if (IsManagedMem(orig))
894893
{
895894
struct MemHeaderExt *mhe_orig = (struct MemHeaderExt *)orig;
@@ -964,7 +963,7 @@ void FreeMemHeader(APTR addr, struct TraceLocation *loc, struct ExecBase *SysBas
964963

965964
IPTR size = (IPTR)mhe->mhe_MemHeader.mh_Upper - (IPTR)addr;
966965

967-
#ifdef HANDLE_MANAGED_MEM
966+
#if HANDLE_MANAGED_MEM
968967
if (IsManagedMem(mhe))
969968
{
970969
if (mhe->mhe_DestroyPool)
@@ -1038,6 +1037,7 @@ APTR InternalAllocPooled(APTR poolHeader, IPTR memSize, ULONG flags, struct Trac
10381037
if (pool->pool.PoolMagic != POOL_MAGIC)
10391038
{
10401039
PoolManagerAlert(PME_ALLOC_INV_POOL, AT_DeadEnd, memSize, NULL, NULL, poolHeader);
1040+
return NULL;
10411041
}
10421042

10431043
if (pool->pool.Requirements & MEMF_SEM_PROTECTED)
@@ -1207,11 +1207,13 @@ void InternalFreePooled(APTR poolHeader, APTR memory, IPTR memSize, struct Trace
12071207
if (pool->pool.PoolMagic != POOL_MAGIC)
12081208
{
12091209
PoolManagerAlert(PME_FREE_INV_POOL, AT_DeadEnd, memSize, memory, poolHeaderMH, NULL);
1210+
return;
12101211
}
12111212

12121213
if (poolHeaderMH != poolHeader)
12131214
{
12141215
PoolManagerAlert(PME_FREE_MXD_POOL, 0, memSize, memory, poolHeaderMH, poolHeader);
1216+
return;
12151217
}
12161218

12171219
if (pool->pool.Requirements & MEMF_SEM_PROTECTED)

rom/exec/memory_nommu.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ APTR nommu_AllocMem(IPTR byteSize, ULONG flags, struct TraceLocation *loc, struc
2525
struct MemHeader *mh;
2626
ULONG requirements = flags & MEMF_PHYSICAL_MASK;
2727

28+
byteSize = (byteSize + MEMCHUNK_TOTAL-1) & ~(MEMCHUNK_TOTAL-1);
29+
2830
/* Protect memory list against other tasks */
2931
MEM_LOCK;
3032

@@ -39,7 +41,7 @@ APTR nommu_AllocMem(IPTR byteSize, ULONG flags, struct TraceLocation *loc, struc
3941
if ((requirements & ~mh->mh_Attributes) || mh->mh_Free < byteSize)
4042
continue;
4143

42-
#ifdef HANDLE_MANAGED_MEM
44+
#if HANDLE_MANAGED_MEM
4345
if (IsManagedMem(mh))
4446
{
4547
struct MemHeaderExt *mhe = (struct MemHeaderExt *)mh;
@@ -73,15 +75,15 @@ APTR nommu_AllocAbs(APTR location, IPTR byteSize, struct ExecBase *SysBase)
7375
/* Loop over MemHeader structures */
7476
ForeachNode(&SysBase->MemList, mh)
7577
{
76-
#ifdef HANDLE_MANAGED_MEM
78+
#if HANDLE_MANAGED_MEM
7779
if (IsManagedMem(mh))
7880
{
7981
struct MemHeaderExt *mhe = (struct MemHeaderExt *)mh;
8082
if (mhe->mhe_InBounds(mhe, location, endlocation))
8183
{
8284
if (mhe->mhe_AllocAbs)
8385
{
84-
APTR ret = mhe->mhe_AllocAbs(mhe, byteSize, location);
86+
ret = mhe->mhe_AllocAbs(mhe, byteSize, location);
8587

8688
MEM_UNLOCK;
8789

@@ -214,7 +216,7 @@ void nommu_FreeMem(APTR memoryBlock, IPTR byteSize, struct TraceLocation *loc, s
214216

215217
ForeachNode(&SysBase->MemList, mh)
216218
{
217-
#ifdef HANDLE_MANAGED_MEM
219+
#if HANDLE_MANAGED_MEM
218220
if (IsManagedMem(mh))
219221
{
220222
struct MemHeaderExt *mhe = (struct MemHeaderExt *)mh;
@@ -280,7 +282,7 @@ IPTR nommu_AvailMem(ULONG attributes, struct ExecBase *SysBase)
280282
D(bug("[MM] Skipping (mh_Attributes = 0x%08X\n", mh->mh_Attributes);)
281283
continue;
282284
}
283-
#ifdef HANDLE_MANAGED_MEM
285+
#if HANDLE_MANAGED_MEM
284286
if (IsManagedMem(mh))
285287
{
286288
struct MemHeaderExt *mhe = (struct MemHeaderExt *)mh;
@@ -327,7 +329,7 @@ IPTR nommu_AvailMem(ULONG attributes, struct ExecBase *SysBase)
327329
/* 2. The end (+1) of the current MemChunk must be lower than the start of the next one. */
328330
if (mc->mc_Next && ((UBYTE *)mc + mc->mc_Bytes >= (UBYTE *)mc->mc_Next))
329331
{
330-
bug("[MM] Chunk allocator error in MemHeader 0x%p\n");
332+
bug("[MM] Chunk allocator error in MemHeader 0x%p\n", mh);
331333
bug("[MM] Overlapping chunks 0x%p (%u bytes) and 0x%p (%u bytes)\n", mc, mc->mc_Bytes, mc->mc_Next, mc->mc_Next->mc_Bytes);
332334

333335
Alert(AN_MemoryInsane|AT_DeadEnd);

0 commit comments

Comments
 (0)