source: trunk/src/odincrt/malloc.cpp@ 21916

Last change on this file since 21916 was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 1.3 KB
Line 
1/** @file
2 * Memory RTL function wrappers for GCC.
3 *
4 * Project Odin Software License can be found in LICENSE.TXT
5 */
6
7#include <odin.h>
8#include <os2sel.h>
9
10#include <memory.h>
11
12#ifdef DEBUG
13unsigned long nrcalls_malloc = 0;
14unsigned long nrcalls_free = 0;
15unsigned long totalmemalloc = 0;
16
17// currently, it's a dumb stub
18void SYSTEM getcrtstat(unsigned long *pnrcalls_malloc,
19 unsigned long *pnrcalls_free,
20 unsigned long *ptotalmemalloc)
21{
22 *pnrcalls_malloc = nrcalls_malloc;
23 *pnrcalls_free = nrcalls_free;
24 *ptotalmemalloc = totalmemalloc;
25}
26#endif
27
28extern "C"
29{
30
31// these are GCC kLIBC exports
32void *_std_malloc(size_t sz);
33void *_std_realloc(void *ptr, size_t sz);
34void *_std_calloc(size_t cnt, size_t sz);
35void _std_free(void *ptr);
36
37void *malloc(size_t sz)
38{
39 unsigned short sel = RestoreOS2FS();
40 void *ptr = _std_malloc(sz);
41 SetFS(sel);
42 return ptr;
43}
44
45void *realloc(void *ptr, size_t sz)
46{
47 unsigned short sel = RestoreOS2FS();
48 void *newPtr = _std_realloc(ptr, sz);
49 SetFS(sel);
50 return newPtr;
51}
52
53void *calloc(size_t cnt, size_t sz)
54{
55 unsigned short sel = RestoreOS2FS();
56 void *ptr = _std_calloc(cnt, sz);
57 SetFS(sel);
58 return ptr;
59}
60
61void free(void *ptr)
62{
63 unsigned short sel = RestoreOS2FS();
64 _std_free(ptr);
65 SetFS(sel);
66}
67
68}
Note: See TracBrowser for help on using the repository browser.