ASN1C C/C++ Common Runtime  ASN1C v7.4.x
rtxMemory.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2020 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 #define RT_MH_TRACE_FREELIST 0x200 /* enable printing of the free element list
51  at certain junctures in the memory
52  management code.
53  Requires building with _MEMTRACE */
54 
55 #define OSRTMH_PROPID_DEFBLKSIZE 1
56 #define OSRTMH_PROPID_SETFLAGS 2
57 #define OSRTMH_PROPID_CLEARFLAGS 3
58 #define OSRTMH_PROPID_KEEPFREEUNITS 4
59 
60 #define OSRTMH_PROPID_USER 10
61 
62 #define OSRTXM_K_MEMBLKSIZ (4*1024)
63 
77 #define OSRTALLOCTYPE(pctxt,type) \
78 (type*) rtxMemHeapAlloc (&(pctxt)->pMemHeap, sizeof(type))
79 
86 #define OSRTALLOCTYPEZ(pctxt,type) \
87 (type*) rtxMemHeapAllocZ (&(pctxt)->pMemHeap, sizeof(type))
88 
100 #define OSRTREALLOCARRAY(pctxt,pseqof,type) do {\
101 if (sizeof(type)*(pseqof)->n < (pseqof)->n) return RTERR_NOMEM; \
102 if (((pseqof)->elem = (type*) rtxMemHeapRealloc \
103 (&(pctxt)->pMemHeap, (pseqof)->elem, sizeof(type)*(pseqof)->n)) == 0) \
104 return RTERR_NOMEM; \
105 } while (0)
106 
107 #ifndef _NO_MALLOC
108 #define OSCRTMALLOC0(nbytes) malloc(nbytes)
109 #define OSCRTFREE0(ptr) free(ptr)
110 #else
111 
112 #ifdef _NO_THREADS
113 extern EXTERNRT OSCTXT g_ctxt;
114 
115 #define OSCRTMALLOC0(nbytes) rtxMemAlloc(&g_ctxt,(nbytes))
116 #define OSCRTFREE0(ptr) rtxMemFreePtr(&g_ctxt,(ptr))
117 #else
118 #define OSCRTMALLOC0(nbytes) (void*)0
119 #define OSCRTFREE0(ptr) (void*)0
120 
121 #endif /* _NO_THREADS */
122 #endif /* _NO_MALLOC */
123 
124 #define OSCRTMALLOC rtxMemAlloc
125 #define OSCRTFREE rtxMemFreePtr
126 
127 struct OSRTDList;
128 
129 #ifdef __cplusplus
130 extern "C" {
131 #endif
132 
133 /* Alias for __cdecl modifier; if __cdecl keyword is not supported,
134  * redefine it as empty macro. */
135 
136 #if !defined(OSCDECL)
137 #if defined(_MSC_VER) || defined(__BORLANDC__)
138 #define OSCDECL __cdecl
139 #else
140 #define OSCDECL
141 #endif
142 #endif /* OSCDECL */
143 
144 EXTERNRT void rtxMemHeapAddRef (void** ppvMemHeap);
145 EXTERNRT void* rtxMemHeapAlloc (void** ppvMemHeap, OSSIZE nbytes);
146 EXTERNRT void* rtxMemHeapAllocZ (void** ppvMemHeap, OSSIZE nbytes);
147 EXTERNRT void* rtxMemHeapSysAlloc (void** ppvMemHeap, OSSIZE nbytes);
148 EXTERNRT void* rtxMemHeapSysAllocZ (void** ppvMemHeap, OSSIZE nbytes);
149 EXTERNRT int rtxMemHeapCheckPtr (void** ppvMemHeap, const void* mem_p);
150 EXTERNRT void rtxMemHeapFreeAll (void** ppvMemHeap);
151 EXTERNRT void rtxMemHeapFreePtr (void** ppvMemHeap, void* mem_p);
152 EXTERNRT void rtxMemHeapSysFreePtr (void** ppvMemHeap, void* mem_p);
153 
154 EXTERNRT void* rtxMemHeapRealloc
155 (void** ppvMemHeap, void* mem_p, OSSIZE nbytes_);
156 
157 EXTERNRT void* rtxMemHeapSysRealloc
158 (void** ppvMemHeap, void* mem_p, OSSIZE nbytes_);
159 
160 EXTERNRT void rtxMemHeapRelease (void** ppvMemHeap);
161 EXTERNRT void rtxMemHeapReset (void** ppvMemHeap);
162 EXTERNRT void rtxMemHeapSetProperty (void** ppvMemHeap,
163  OSUINT32 propId, void* pProp);
164 
165 EXTERNRT void* rtxMemNewArray (OSSIZE nbytes);
166 EXTERNRT void* rtxMemNewArrayZ (OSSIZE nbytes);
167 EXTERNRT void rtxMemDeleteArray (void* mem_p);
168 
169 EXTERNRT void* rtxMemHeapAutoPtrRef (void** ppvMemHeap, void* ptr);
170 EXTERNRT int rtxMemHeapAutoPtrUnref (void** ppvMemHeap, void* ptr);
171 EXTERNRT int rtxMemHeapAutoPtrGetRefCount (void** ppvMemHeap, void* mem_p);
172 
173 EXTERNRT void rtxMemHeapInvalidPtrHook (void** ppvMemHeap, const void* mem_p);
174 
175 EXTERNRT void rtxMemHeapCheck (void **ppvMemHeap, const char* file, int line);
176 
180 EXTERNRT void rtxMemHeapPrint (void **ppvMemHeap);
181 
186 EXTERNRT void rtxMemHeapPrintWithFree (void **ppvMemHeap);
187 
196 EXTERNRT int rtxMemHeapCreate (void** ppvMemHeap);
197 
210 EXTERNRT int rtxMemHeapCreateExt (void** ppvMemHeap,
211  OSMallocFunc malloc_func,
212  OSReallocFunc realloc_func,
213  OSFreeFunc free_func);
214 
228 EXTERNRT int rtxMemStaticHeapCreate
229 (void **ppvMemHeap, void* pmem, OSSIZE memsize) ;
230 
231 #if !defined(_ARMTCC) && !defined(__SYMBIAN32__)
232 
247 EXTERNRT void rtxMemSetAllocFuncs (OSMallocFunc malloc_func,
248  OSReallocFunc realloc_func,
249  OSFreeFunc free_func);
250 
251 #endif /* __SYMBIAN32__ */
252 
253 EXTERNRT void rtxMemFreeOpenSeqExt
254 (OSCTXT* pctxt, struct OSRTDList *pElemList);
255 
262 EXTERNRT OSUINT32 rtxMemHeapGetDefBlkSize (OSCTXT* pctxt);
263 
264 #ifndef __SYMBIAN32__
265 
272 EXTERNRT void rtxMemSetDefBlkSize (OSUINT32 blkSize);
273 #endif
274 
281 EXTERNRT OSUINT32 rtxMemGetDefBlkSize (OSVOIDARG);
282 
290 EXTERNRT OSBOOL rtxMemHeapIsEmpty (OSCTXT* pctxt);
291 
300 EXTERNRT OSBOOL rtxMemIsZero (const void* pmem, OSSIZE memsiz);
301 
302 #ifdef _STATIC_HEAP
303 EXTERNRT void rtxMemSetStaticBuf (void* memHeapBuf, OSUINT32 blkSize);
304 #endif
305 
315 #define rtxMemAlloc(pctxt,nbytes) \
316 rtxMemHeapAlloc(&(pctxt)->pMemHeap,nbytes)
317 
328 #define rtxMemSysAlloc(pctxt,nbytes) \
329 rtxMemHeapSysAlloc(&(pctxt)->pMemHeap,nbytes)
330 
340 #define rtxMemAllocZ(pctxt,nbytes) \
341 rtxMemHeapAllocZ(&(pctxt)->pMemHeap,nbytes)
342 
356 #define rtxMemSysAllocZ(pctxt,nbytes) \
357 rtxMemHeapSysAllocZ(&(pctxt)->pMemHeap,nbytes)
358 
359 
374 #define rtxMemRealloc(pctxt,mem_p,nbytes) \
375 rtxMemHeapRealloc(&(pctxt)->pMemHeap, (void*)mem_p, nbytes)
376 
393 #define rtxMemSysRealloc(pctxt,mem_p,nbytes) \
394  rtxMemHeapSysRealloc(&(pctxt)->pMemHeap,(void*)mem_p,nbytes)
395 
407 #define rtxMemFreePtr(pctxt,mem_p) \
408 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
409 
420 #define rtxMemSysFreePtr(pctxt,mem_p) \
421 rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
422 
431 EXTERNRT void rtxMemFree (OSCTXT* pctxt);
432 
447 EXTERNRT void rtxMemReset (OSCTXT* pctxt);
448 
458 #define rtxMemAllocType(pctxt,ctype) \
459 (ctype*)rtxMemHeapAlloc(&(pctxt)->pMemHeap,sizeof(ctype))
460 
474 #define rtxMemSysAllocType(pctxt,ctype) \
475 (ctype*)rtxMemHeapSysAlloc(&(pctxt)->pMemHeap,sizeof(ctype))
476 
486 #define rtxMemAllocTypeZ(pctxt,ctype) \
487 (ctype*)rtxMemHeapAllocZ(&(pctxt)->pMemHeap,sizeof(ctype))
488 
502 #define rtxMemSysAllocTypeZ(pctxt,ctype) \
503 (ctype*)rtxMemHeapSysAllocZ(&(pctxt)->pMemHeap,sizeof(ctype))
504 
516 #define rtxMemFreeType(pctxt,mem_p) \
517 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
518 
530 #define rtxMemSysFreeType(pctxt,mem_p) \
531 rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
532 
542 #define rtxMemAllocArray(pctxt,n,type) \
543 (type*)rtxMemAllocArray2 (pctxt, n, sizeof(type), 0)
544 
545 EXTERNRT void* rtxMemAllocArray2
546 (OSCTXT* pctxt, OSSIZE numElements, OSSIZE typeSize, OSUINT32 flags);
547 
561 #define rtxMemSysAllocArray(pctxt,n,type) \
562 (type*)rtxMemAllocArray2 (pctxt, n, sizeof(type), RT_MH_SYSALLOC)
563 
573 #define rtxMemAllocArrayZ(pctxt,n,type) \
574 (type*)rtxMemAllocArray2 (pctxt, n, sizeof(type), RT_MH_ZEROARRAY)
575 
587 #define rtxMemFreeArray(pctxt,mem_p) \
588 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
589 
601 #define rtxMemSysFreeArray(pctxt,mem_p) \
602 rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
603 
618 #define rtxMemReallocArray(pctxt,mem_p,n,type) \
619 (type*)rtxMemHeapRealloc(&(pctxt)->pMemHeap, (void*)mem_p, sizeof(type)*n)
620 
621 /* Auto-pointer functions */
634 #define rtxMemNewAutoPtr(pctxt,nbytes) \
635 rtxMemHeapAlloc(&(pctxt)->pMemHeap, nbytes)
636 
645 #define rtxMemAutoPtrRef(pctxt,ptr) \
646 rtxMemHeapAutoPtrRef(&(pctxt)->pMemHeap, (void*)(ptr))
647 
658 #define rtxMemAutoPtrUnref(pctxt,ptr) \
659 rtxMemHeapAutoPtrUnref(&(pctxt)->pMemHeap, (void*)(ptr))
660 
669 #define rtxMemAutoPtrGetRefCount(pctxt,ptr) \
670 rtxMemHeapAutoPtrGetRefCount(&(pctxt)->pMemHeap, (void*)(ptr))
671 
680 #define rtxMemCheckPtr(pctxt,mem_p) \
681 rtxMemHeapCheckPtr(&(pctxt)->pMemHeap, (void*)mem_p)
682 
688 #define rtxMemCheck(pctxt) \
689 rtxMemHeapCheck(&(pctxt)->pMemHeap, __FILE__, __LINE__)
690 
696 #define rtxMemPrint(pctxt) \
697 rtxMemHeapPrint(&(pctxt)->pMemHeap)
698 
705 #define rtxMemPrintWithFree(pctxt) \
706 rtxMemHeapPrintWithFree(&(pctxt)->pMemHeap)
707 
715 #define rtxMemSetProperty(pctxt,propId,pProp) \
716 rtxMemHeapSetProperty (&(pctxt)->pMemHeap, propId, pProp)
717 
718 
719 #ifdef __cplusplus
720 }
721 #endif
722 
725 #endif /*__RTXMEMORY_H__*/
OSUINT32 rtxMemGetDefBlkSize(OSVOIDARG)
OSUINT32 rtxMemHeapGetDefBlkSize(OSCTXT *pctxt)
Definition: rtxDList.h:64
OSBOOL rtxMemIsZero(const void *pmem, OSSIZE memsiz)
void rtxMemHeapPrintWithFree(void **ppvMemHeap)
void rtxMemHeapPrint(void **ppvMemHeap)
void rtxMemReset(OSCTXT *pctxt)
int rtxMemStaticHeapCreate(void **ppvMemHeap, void *pmem, OSSIZE memsize)
int rtxMemHeapCreateExt(void **ppvMemHeap, OSMallocFunc malloc_func, OSReallocFunc realloc_func, OSFreeFunc free_func)
void rtxMemSetAllocFuncs(OSMallocFunc malloc_func, OSReallocFunc realloc_func, OSFreeFunc free_func)
int rtxMemHeapCreate(void **ppvMemHeap)
OSBOOL rtxMemHeapIsEmpty(OSCTXT *pctxt)
void rtxMemSetDefBlkSize(OSUINT32 blkSize)
Definition: rtxContext.h:189
void rtxMemFree(OSCTXT *pctxt)