source: trunk/src/odincrt/malloc.cpp

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

Merge branch gcc-kmk to trunk.

File size: 1.3 KB
RevLine 
[21794]1/** @file
2 * Memory RTL function wrappers for GCC.
3 *
4 * Project Odin Software License can be found in LICENSE.TXT
5 */
6
[21823]7#include <odin.h>
[21794]8#include <os2sel.h>
9
[21823]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
[21826]18void SYSTEM getcrtstat(unsigned long *pnrcalls_malloc,
19 unsigned long *pnrcalls_free,
20 unsigned long *ptotalmemalloc)
[21823]21{
22 *pnrcalls_malloc = nrcalls_malloc;
23 *pnrcalls_free = nrcalls_free;
24 *ptotalmemalloc = totalmemalloc;
25}
26#endif
27
[21794]28extern "C"
29{
30
31// these are GCC kLIBC exports
[21823]32void *_std_malloc(size_t sz);
[21794]33void *_std_realloc(void *ptr, size_t sz);
34void *_std_calloc(size_t cnt, size_t sz);
35void _std_free(void *ptr);
36
[21823]37void *malloc(size_t sz)
[21794]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);
[21823]58 return ptr;
[21794]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.