Fix IO memory access .. SB128 driver makes noises in VMWare - CMI is untested (Curren...
[AROS.git] / rom / exec / deletepool.c
blobda20a50436709ced47b7a9a97404a74d20e06d35
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Delete a memory pool including all its memory.
6 Lang: english
7 */
9 #include <aros/libcall.h>
10 #include <exec/memory.h>
11 #include <proto/exec.h>
13 #include "exec_intern.h"
14 #include "exec_util.h"
15 #include "memory.h"
16 #include "mungwall.h"
18 /*****************************************************************************
20 NAME */
22 AROS_LH1(void, DeletePool,
24 /* SYNOPSIS */
25 AROS_LHA(APTR, poolHeader, A0),
27 /* LOCATION */
28 struct ExecBase *, SysBase, 117, Exec)
30 /* FUNCTION
31 Delete a pool including all it's memory.
33 INPUTS
34 poolHeader - The pool allocated with CreatePool() or NULL.
36 RESULT
38 NOTES
40 EXAMPLE
42 BUGS
44 SEE ALSO
45 CreatePool(), AllocPooled(), FreePooled()
47 INTERNALS
49 ******************************************************************************/
51 AROS_LIBFUNC_INIT
53 ASSERT_VALID_PTR_OR_NULL(poolHeader);
55 D(bug("[exec] DeletePool(0x%p)\n", poolHeader));
57 /* It is legal to DeletePool(NULL) */
58 if (poolHeader != NULL)
60 struct Pool *pool = poolHeader + MEMHEADER_TOTAL;
61 struct Node *p, *p2; /* Avoid casts */
63 D(bug("[DeletePool] Pool header 0x%p\n", pool));
66 * We are going to deallocate the whole pool.
67 * Scan mungwall's allocations list and remove all chunks
68 * belonging to the pool.
69 * For mungwall we provide also called function name, return address and caller's stack frame.
70 * This will be displayed in alerts.
72 MungWall_Scan(pool, "DeletePool", __builtin_return_address(0), CALLER_FRAME, SysBase);
75 * Free the list of puddles.
76 * Remember that initial puddle containing the pool structure is also in this list.
77 * We do not need to free it until everything else is freed.
79 for (p = (struct Node *)pool->PuddleList.mlh_Head; p->ln_Succ; p = p2)
81 p2 = p->ln_Succ;
83 D(bug("[DeletePool] Puddle 0x%p...", p));
85 if (p != poolHeader)
87 D(bug(" freeing"));
88 FreeMemHeader(p, SysBase);
90 D(bug("\n"));
93 /* Free the last puddle, containing the pool header */
94 D(bug("[DeletePool] Freeing initial puddle 0x%p\n", poolHeader));
95 FreeMemHeader(poolHeader, SysBase);
98 AROS_LIBFUNC_EXIT
99 } /* DeletePool */