use same location as .configured, etc, to store .files-touched
[AROS.git] / compiler / clib / malloc.c
blob07c11349eda6e25d4c7f53427aaff9dbcea1bde7
1 /*
2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C function malloc().
6 */
8 #include "__arosc_privdata.h"
10 #define DEBUG 0
12 #include <errno.h>
13 #include <dos/dos.h>
14 #include <exec/memory.h>
15 #include <proto/exec.h>
16 #include <aros/symbolsets.h>
17 #include <aros/debug.h>
19 /*****************************************************************************
21 NAME */
22 #include <sys/types.h>
23 #include <stdlib.h>
25 void *malloc (
27 /* SYNOPSIS */
28 size_t size)
30 /* FUNCTION
31 Allocate size bytes of memory and return the address of the
32 first byte.
34 INPUTS
35 size - How much memory to allocate.
37 RESULT
38 A pointer to the allocated memory or NULL. If you don't need the
39 memory anymore, you can pass this pointer to free(). If you don't,
40 the memory will be freed for you when the application exits.
42 NOTES
43 This function must not be used in a shared library or in a threaded
44 application.
46 EXAMPLE
48 BUGS
50 SEE ALSO
51 free()
53 INTERNALS
55 ******************************************************************************/
57 UBYTE *mem = NULL;
59 /* Allocate the memory */
60 mem = AllocPooled (__mempool, size + AROS_ALIGN(sizeof(size_t)));
61 if (mem)
63 *((size_t *)mem) = size;
64 mem += AROS_ALIGN(sizeof(size_t));
66 else
67 errno = ENOMEM;
69 return mem;
71 } /* malloc */
74 int __init_memstuff(void)
76 D(bug("__init_memstuff: task(%x), privdata(%x)\n",
77 FindTask(NULL), __get_arosc_privdata()
78 ));
80 __mempool = CreatePool(MEMF_ANY | MEMF_SEM_PROTECTED, 65536L, 4096L);
82 D(bug("__init_memstuff: __mempool(%x)\n", __mempool));
84 if (!__mempool)
86 return 0;
89 return 1;
93 void __exit_memstuff(void)
95 D(bug("__exit_memstuff: task(%x), privdata(%x), __mempool(%x)\n",
96 FindTask(NULL), __get_arosc_privdata(), __mempool
97 ));
99 if (__mempool)
101 DeletePool(__mempool);
105 ADD2INIT(__init_memstuff, 0);
106 ADD2EXIT(__exit_memstuff, 0);