XBinder  Version 2.6.x
rtxMemory.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2018 Objective Systems, Inc.
3  *
4  * This software is furnished under a license and may be used and copied
5  * only in accordance with the terms of such license and with the
6  * inclusion of the above copyright notice. This software or any other
7  * copies thereof may not be provided or otherwise made available to any
8  * other person. No title to and ownership of the software is hereby
9  * transferred.
10  *
11  * The information in this software is subject to change without notice
12  * and should not be construed as a commitment by Objective Systems, Inc.
13  *
14  * PROPRIETARY NOTICE
15  *
16  * This software is an unpublished work subject to a confidentiality agreement
17  * and is protected by copyright and trade secret law. Unauthorized copying,
18  * redistribution or other use of this work is prohibited.
19  *
20  * The above notice of copyright on this source code product does not indicate
21  * any actual or intended publication of such source code.
22  *
23  *****************************************************************************/
28 #ifndef __RTXMEMORY_H__
29 #define __RTXMEMORY_H__
30 
31 #include "rtxsrc/rtxContext.h"
32 
33 /*
34  * Uncomment this definition before building the C or C++ run-time
35  * libraries to enable compact memory management. This will have a
36  * smaller code footprint than the standard memory management, however,
37  * the performance may not be as good.
38  */
39 /*#define _MEMCOMPACT*/
40 
41 #define RT_MH_DONTKEEPFREE 0x1
42 #define RT_MH_VALIDATEPTR 0x2
43 #define RT_MH_CHECKHEAP 0x4
44 #define RT_MH_TRACE 0x8
45 #define RT_MH_DIAG 0x10
46 #define RT_MH_DIAG_DEBUG 0x20
47 #define RT_MH_ZEROONFREE 0x40
48 #define RT_MH_ZEROARRAY 0x80
49 #define RT_MH_SYSALLOC 0x100
50 
51 #define OSRTMH_PROPID_DEFBLKSIZE 1
52 #define OSRTMH_PROPID_SETFLAGS 2
53 #define OSRTMH_PROPID_CLEARFLAGS 3
54 #define OSRTMH_PROPID_KEEPFREEUNITS 4
55 
56 #define OSRTMH_PROPID_USER 10
57 
58 #define OSRTXM_K_MEMBLKSIZ (4*1024)
59 
73 #define OSRTALLOCTYPE(pctxt,type) \
74 (type*) rtxMemHeapAlloc (&(pctxt)->pMemHeap, sizeof(type))
75 
82 #define OSRTALLOCTYPEZ(pctxt,type) \
83 (type*) rtxMemHeapAllocZ (&(pctxt)->pMemHeap, sizeof(type))
84 
96 #define OSRTREALLOCARRAY(pctxt,pseqof,type) do {\
97 if (sizeof(type)*(pseqof)->n < (pseqof)->n) return RTERR_NOMEM; \
98 if (((pseqof)->elem = (type*) rtxMemHeapRealloc \
99 (&(pctxt)->pMemHeap, (pseqof)->elem, sizeof(type)*(pseqof)->n)) == 0) \
100 return RTERR_NOMEM; \
101 } while (0)
102 
103 #ifndef _NO_MALLOC
104 #define OSCRTMALLOC0(nbytes) malloc(nbytes)
105 #define OSCRTFREE0(ptr) free(ptr)
106 #else
107 
108 #ifdef _NO_THREADS
109 extern EXTERNRT OSCTXT g_ctxt;
110 
111 #define OSCRTMALLOC0(nbytes) rtxMemAlloc(&g_ctxt,(nbytes))
112 #define OSCRTFREE0(ptr) rtxMemFreePtr(&g_ctxt,(ptr))
113 #else
114 #define OSCRTMALLOC0(nbytes) (void*)0
115 #define OSCRTFREE0(ptr) (void*)0
116 
117 #endif /* _NO_THREADS */
118 #endif /* _NO_MALLOC */
119 
120 #define OSCRTMALLOC rtxMemAlloc
121 #define OSCRTFREE rtxMemFreePtr
122 
123 struct OSRTDList;
124 
125 #ifdef __cplusplus
126 extern "C" {
127 #endif
128 
129 /* Alias for __cdecl modifier; if __cdecl keyword is not supported,
130  * redefine it as empty macro. */
131 
132 #if !defined(OSCDECL)
133 #if defined(_MSC_VER) || defined(__BORLANDC__)
134 #define OSCDECL __cdecl
135 #else
136 #define OSCDECL
137 #endif
138 #endif /* OSCDECL */
139 
140 EXTERNRT void rtxMemHeapAddRef (void** ppvMemHeap);
141 EXTERNRT void* rtxMemHeapAlloc (void** ppvMemHeap, size_t nbytes);
142 EXTERNRT void* rtxMemHeapAllocZ (void** ppvMemHeap, size_t nbytes);
143 EXTERNRT void* rtxMemHeapSysAlloc (void** ppvMemHeap, size_t nbytes);
144 EXTERNRT void* rtxMemHeapSysAllocZ (void** ppvMemHeap, size_t nbytes);
145 EXTERNRT int rtxMemHeapCheckPtr (void** ppvMemHeap, const void* mem_p);
146 EXTERNRT void rtxMemHeapFreeAll (void** ppvMemHeap);
147 EXTERNRT void rtxMemHeapFreePtr (void** ppvMemHeap, void* mem_p);
148 EXTERNRT void rtxMemHeapSysFreePtr (void** ppvMemHeap, void* mem_p);
149 
150 EXTERNRT void* rtxMemHeapRealloc
151 (void** ppvMemHeap, void* mem_p, size_t nbytes_);
152 
153 EXTERNRT void* rtxMemHeapSysRealloc
154 (void** ppvMemHeap, void* mem_p, size_t nbytes_);
155 
156 EXTERNRT void rtxMemHeapRelease (void** ppvMemHeap);
157 EXTERNRT void rtxMemHeapReset (void** ppvMemHeap);
158 EXTERNRT void rtxMemHeapSetProperty (void** ppvMemHeap,
159  OSUINT32 propId, void* pProp);
160 
161 EXTERNRT void* rtxMemNewArray (size_t nbytes);
162 EXTERNRT void* rtxMemNewArrayZ (size_t nbytes);
163 EXTERNRT void rtxMemDeleteArray (void* mem_p);
164 
165 EXTERNRT void* rtxMemHeapAutoPtrRef (void** ppvMemHeap, void* ptr);
166 EXTERNRT int rtxMemHeapAutoPtrUnref (void** ppvMemHeap, void* ptr);
167 EXTERNRT int rtxMemHeapAutoPtrGetRefCount (void** ppvMemHeap, void* mem_p);
168 
169 EXTERNRT void rtxMemHeapInvalidPtrHook (void** ppvMemHeap, const void* mem_p);
170 
171 EXTERNRT void rtxMemHeapCheck (void **ppvMemHeap, const char* file, int line);
172 EXTERNRT void rtxMemHeapPrint (void **ppvMemHeap);
173 
182 EXTERNRT int rtxMemHeapCreate (void** ppvMemHeap);
183 
196 EXTERNRT int rtxMemHeapCreateExt (void** ppvMemHeap,
197  OSMallocFunc malloc_func,
198  OSReallocFunc realloc_func,
199  OSFreeFunc free_func);
200 
214 EXTERNRT int rtxMemStaticHeapCreate
215 (void **ppvMemHeap, void* pmem, size_t memsize) ;
216 
217 #if !defined(_ARMTCC) && !defined(__SYMBIAN32__)
218 
233 EXTERNRT void rtxMemSetAllocFuncs (OSMallocFunc malloc_func,
234  OSReallocFunc realloc_func,
235  OSFreeFunc free_func);
236 
237 #endif /* __SYMBIAN32__ */
238 
239 EXTERNRT void rtxMemFreeOpenSeqExt
240 (OSCTXT* pctxt, struct OSRTDList *pElemList);
241 
248 EXTERNRT OSUINT32 rtxMemHeapGetDefBlkSize (OSCTXT* pctxt);
249 
250 #ifndef __SYMBIAN32__
251 
258 EXTERNRT void rtxMemSetDefBlkSize (OSUINT32 blkSize);
259 #endif
260 
267 EXTERNRT OSUINT32 rtxMemGetDefBlkSize (OSVOIDARG);
268 
276 EXTERNRT OSBOOL rtxMemHeapIsEmpty (OSCTXT* pctxt);
277 
286 EXTERNRT OSBOOL rtxMemIsZero (const void* pmem, size_t memsiz);
287 
288 #ifdef _STATIC_HEAP
289 EXTERNRT void rtxMemSetStaticBuf (void* memHeapBuf, OSUINT32 blkSize);
290 #endif
291 
301 #define rtxMemAlloc(pctxt,nbytes) \
302 rtxMemHeapAlloc(&(pctxt)->pMemHeap,nbytes)
303 
314 #define rtxMemSysAlloc(pctxt,nbytes) \
315 rtxMemHeapSysAlloc(&(pctxt)->pMemHeap,nbytes)
316 
326 #define rtxMemAllocZ(pctxt,nbytes) \
327 rtxMemHeapAllocZ(&(pctxt)->pMemHeap,nbytes)
328 
342 #define rtxMemSysAllocZ(pctxt,nbytes) \
343 rtxMemHeapSysAllocZ(&(pctxt)->pMemHeap,nbytes)
344 
345 
360 #define rtxMemRealloc(pctxt,mem_p,nbytes) \
361 rtxMemHeapRealloc(&(pctxt)->pMemHeap, (void*)mem_p, nbytes)
362 
379 #define rtxMemSysRealloc(pctxt,mem_p,nbytes) \
380  rtxMemHeapSysRealloc(&(pctxt)->pMemHeap,(void*)mem_p,nbytes)
381 
393 #define rtxMemFreePtr(pctxt,mem_p) \
394 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
395 
406 #define rtxMemSysFreePtr(pctxt,mem_p) \
407 rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
408 
417 EXTERNRT void rtxMemFree (OSCTXT* pctxt);
418 
433 EXTERNRT void rtxMemReset (OSCTXT* pctxt);
434 
444 #define rtxMemAllocType(pctxt,ctype) \
445 (ctype*)rtxMemHeapAlloc(&(pctxt)->pMemHeap,sizeof(ctype))
446 
460 #define rtxMemSysAllocType(pctxt,ctype) \
461 (ctype*)rtxMemHeapSysAlloc(&(pctxt)->pMemHeap,sizeof(ctype))
462 
472 #define rtxMemAllocTypeZ(pctxt,ctype) \
473 (ctype*)rtxMemHeapAllocZ(&(pctxt)->pMemHeap,sizeof(ctype))
474 
488 #define rtxMemSysAllocTypeZ(pctxt,ctype) \
489 (ctype*)rtxMemHeapSysAllocZ(&(pctxt)->pMemHeap,sizeof(ctype))
490 
502 #define rtxMemFreeType(pctxt,mem_p) \
503 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
504 
516 #define rtxMemSysFreeType(pctxt,mem_p) \
517 rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
518 
528 #define rtxMemAllocArray(pctxt,n,type) \
529 (type*)rtxMemAllocArray2 (pctxt, n, sizeof(type), 0)
530 
531 EXTERNRT void* rtxMemAllocArray2
532 (OSCTXT* pctxt, OSSIZE numElements, OSSIZE typeSize, OSUINT32 flags);
533 
547 #define rtxMemSysAllocArray(pctxt,n,type) \
548 (type*)rtxMemAllocArray2 (pctxt, n, sizeof(type), RT_MH_SYSALLOC)
549 
559 #define rtxMemAllocArrayZ(pctxt,n,type) \
560 (type*)rtxMemAllocArray2 (pctxt, n, sizeof(type), RT_MH_ZEROARRAY)
561 
573 #define rtxMemFreeArray(pctxt,mem_p) \
574 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
575 
587 #define rtxMemSysFreeArray(pctxt,mem_p) \
588 rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
589 
604 #define rtxMemReallocArray(pctxt,mem_p,n,type) \
605 (type*)rtxMemHeapRealloc(&(pctxt)->pMemHeap, (void*)mem_p, sizeof(type)*n)
606 
607 /* Auto-pointer functions */
620 #define rtxMemNewAutoPtr(pctxt,nbytes) \
621 rtxMemHeapAlloc(&(pctxt)->pMemHeap, nbytes)
622 
631 #define rtxMemAutoPtrRef(pctxt,ptr) \
632 rtxMemHeapAutoPtrRef(&(pctxt)->pMemHeap, (void*)(ptr))
633 
644 #define rtxMemAutoPtrUnref(pctxt,ptr) \
645 rtxMemHeapAutoPtrUnref(&(pctxt)->pMemHeap, (void*)(ptr))
646 
655 #define rtxMemAutoPtrGetRefCount(pctxt,ptr) \
656 rtxMemHeapAutoPtrGetRefCount(&(pctxt)->pMemHeap, (void*)(ptr))
657 
666 #define rtxMemCheckPtr(pctxt,mem_p) \
667 rtxMemHeapCheckPtr(&(pctxt)->pMemHeap, (void*)mem_p)
668 
674 #define rtxMemCheck(pctxt) \
675 rtxMemHeapCheck(&(pctxt)->pMemHeap, __FILE__, __LINE__)
676 
682 #define rtxMemPrint(pctxt) \
683 rtxMemHeapPrint(&(pctxt)->pMemHeap)
684 
692 #define rtxMemSetProperty(pctxt,propId,pProp) \
693 rtxMemHeapSetProperty (&(pctxt)->pMemHeap, propId, pProp)
694 
695 
696 #ifdef __cplusplus
697 }
698 #endif
699 
702 #endif /*__RTXMEMORY_H__*/
EXTERNRT OSBOOL rtxMemIsZero(const void *pmem, size_t memsiz)
This helper function determines if an arbitrarily sized block of memory is set to zero...
This is the main list structure.
Definition: rtxDList.h:64
EXTERNRT OSUINT32 rtxMemHeapGetDefBlkSize(OSCTXT *pctxt)
This function returns the actual granularity of memory blocks in the context.
EXTERNRT int rtxMemHeapCreate(void **ppvMemHeap)
This function creates a standard memory heap.
Common run-time context definitions.
EXTERNRT void rtxMemFree(OSCTXT *pctxt)
Free memory associated with a context.
EXTERNRT int rtxMemStaticHeapCreate(void **ppvMemHeap, void *pmem, size_t memsize)
This function creates a static memory heap.
EXTERNRT void rtxMemSetAllocFuncs(OSMallocFunc malloc_func, OSReallocFunc realloc_func, OSFreeFunc free_func)
This function sets the pointers to standard allocation functions.
EXTERNRT int rtxMemHeapCreateExt(void **ppvMemHeap, OSMallocFunc malloc_func, OSReallocFunc realloc_func, OSFreeFunc free_func)
This function creates a standard memory heap and sets the low-level memory functions to the specified...
EXTERNRT OSBOOL rtxMemHeapIsEmpty(OSCTXT *pctxt)
This function determines if the memory heap defined in the give context is empty (i.e.
EXTERNRT void rtxMemReset(OSCTXT *pctxt)
Reset memory associated with a context.
EXTERNRT void rtxMemSetDefBlkSize(OSUINT32 blkSize)
This function sets the minimum size and the granularity of memory blocks for newly created memory hea...
Run-time context structure.
Definition: rtxContext.h:185
EXTERNRT OSUINT32 rtxMemGetDefBlkSize(OSVOIDARG)
This function returns the actual granularity of memory blocks.