2 Copyright � 1995-2011, The AROS Development Team. All rights reserved.
11 #include <exec/lists.h>
12 #include <exec/semaphores.h>
13 #include <exec/memory.h>
16 #if defined(__AROSEXEC_SMP__)
17 #define MEM_LOCK do { Forbid(); EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->MemListSpinLock, NULL, SPINLOCK_MODE_WRITE); } while(0)
18 #define MEM_LOCK_SHARED do { Forbid(); EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->MemListSpinLock, NULL, SPINLOCK_MODE_READ); } while(0)
19 #define MEM_UNLOCK do { EXEC_SPINLOCK_UNLOCK(&PrivExecBase(SysBase)->MemListSpinLock); Permit(); } while(0)
21 #if defined(__AROSEXEC_BROKENMEMLOCK__)
22 #define MEM_LOCK ObtainSemaphore(&PrivExecBase(SysBase)->MemListSem)
23 #define MEM_LOCK_SHARED ObtainSemaphoreShared(&PrivExecBase(SysBase)->MemListSem)
24 #define MEM_UNLOCK ReleaseSemaphore(&PrivExecBase(SysBase)->MemListSem)
26 #define MEM_LOCK Forbid()
27 #define MEM_LOCK_SHARED Forbid()
28 #define MEM_UNLOCK Permit()
32 #define POOL_MAGIC AROS_MAKE_ID('P','o','O','l')
34 /* Private Pool structure */
37 struct MinList PuddleList
;
46 struct SignalSemaphore sem
;
55 struct checkMemHandlersState
57 struct Node
*cmhs_CurNode
;
58 struct MemHandlerData cmhs_Data
;
63 struct MemHeaderAllocatorCtx
;
65 /* Returns existing or allocates new ctx */
66 struct MemHeaderAllocatorCtx
* mhac_GetSysCtx(struct MemHeader
* mh
, struct ExecBase
* SysBase
);
67 void mhac_PoolMemHeaderSetup(struct MemHeader
* mh
, struct ProtectedPool
* pool
);
68 ULONG
mhac_GetCtxSize();
69 /* Clears ctx if it already exists for a given MemHeader */
70 void mhac_ClearSysCtx(struct MemHeader
* mh
, struct ExecBase
* SysBase
);
72 struct MemHeader
*FindMem(APTR address
, struct ExecBase
*SysBase
);
73 APTR
stdAlloc(struct MemHeader
*mh
, struct MemHeaderAllocatorCtx
*mhac
, IPTR byteSize
, ULONG requirements
, struct TraceLocation
*loc
, struct ExecBase
*SysBase
);
74 void stdDealloc(struct MemHeader
*freeList
, struct MemHeaderAllocatorCtx
*mhac
, APTR memoryBlock
, IPTR byteSize
, struct TraceLocation
*loc
, struct ExecBase
*SysBase
);
76 APTR
InternalAllocAbs(APTR location
, IPTR byteSize
, struct ExecBase
*SysBase
);
77 void InternalFreeMem(APTR location
, IPTR byteSize
, struct TraceLocation
*loc
, struct ExecBase
*SysBase
);
78 APTR
AllocMemHeader(IPTR size
, ULONG flags
, struct TraceLocation
*loc
, struct ExecBase
*SysBase
);
79 void FreeMemHeader(APTR addr
, struct TraceLocation
*loc
, struct ExecBase
*SysBase
);
81 APTR
InternalAllocPooled(APTR poolHeader
, IPTR memSize
, ULONG flags
, struct TraceLocation
*loc
, struct ExecBase
*SysBase
);
82 void InternalFreePooled(APTR poolHeader
, APTR memory
, IPTR memSize
, struct TraceLocation
*loc
, struct ExecBase
*SysBase
);
84 ULONG
checkMemHandlers(struct checkMemHandlersState
*cmhs
, struct ExecBase
*SysBase
);
86 APTR
nommu_AllocMem(IPTR byteSize
, ULONG flags
, struct TraceLocation
*loc
, struct ExecBase
*SysBase
);
87 APTR
nommu_AllocAbs(APTR location
, IPTR byteSize
, struct ExecBase
*SysBase
);
88 void nommu_FreeMem(APTR memoryBlock
, IPTR byteSize
, struct TraceLocation
*loc
, struct ExecBase
*SysBase
);
89 IPTR
nommu_AvailMem(ULONG attributes
, struct ExecBase
*SysBase
);
91 #define PME_FREE_NO_CHUNK 1
92 #define PME_FREE_INV_POOL 2
93 #define PME_FREE_MXD_POOL 3
94 #define PME_ALLOC_INV_POOL 4
95 #define PME_DEL_POOL_INV_POOL 5
97 void PoolManagerAlert(ULONG code
, ULONG flags
, IPTR memSize
, APTR memory
, APTR poolHeaderMH
, APTR poolHeader
);
100 ((sizeof(struct Block)+AROS_WORSTALIGN-1)&~(AROS_WORSTALIGN-1))