VirtualBox

source: vbox/trunk/include/iprt/mem.h@ 83368

Last change on this file since 83368 was 83368, checked in by vboxsync, 5 years ago

IPRT: Added RTMemAllocZ and RTMemEfReallocZ[NP].

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 43.4 KB
Line 
1/** @file
2 * IPRT - Memory Management and Manipulation.
3 */
4
5/*
6 * Copyright (C) 2006-2020 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef IPRT_INCLUDED_mem_h
27#define IPRT_INCLUDED_mem_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32
33#include <iprt/cdefs.h>
34#include <iprt/types.h>
35
36#ifdef IPRT_WITH_GCC_SANITIZER
37# include <sanitizer/lsan_interface.h>
38#endif
39
40#ifdef IN_RC
41# error "There are no RTMem APIs available Guest Context!"
42#endif
43
44
45/** @defgroup grp_rt_mem RTMem - Memory Management and Manipulation
46 * @ingroup grp_rt
47 * @{
48 */
49
50RT_C_DECLS_BEGIN
51
52/** @def RTMEM_ALIGNMENT
53 * The alignment of the memory blocks returned by RTMemAlloc(), RTMemAllocZ(),
54 * RTMemRealloc(), RTMemTmpAlloc() and RTMemTmpAllocZ() for allocations greater
55 * than RTMEM_ALIGNMENT.
56 *
57 * @note This alignment is not forced if the electric fence is active!
58 */
59#if defined(RT_OS_OS2)
60# define RTMEM_ALIGNMENT 4
61#else
62# define RTMEM_ALIGNMENT 8
63#endif
64
65/** @def RTMEM_TAG
66 * The default allocation tag used by the RTMem allocation APIs.
67 *
68 * When not defined before the inclusion of iprt/mem.h or iprt/memobj.h, this
69 * will default to the pointer to the current file name. The memory API will
70 * make of use of this as pointer to a volatile but read-only string.
71 * The alternative tag includes the line number for a more-detailed analysis.
72 */
73#ifndef RTMEM_TAG
74# if 0
75# define RTMEM_TAG (__FILE__ ":" RT_XSTR(__LINE__))
76# else
77# define RTMEM_TAG (__FILE__)
78# endif
79#endif
80
81
82/** @name Allocate temporary memory.
83 * @{ */
84/**
85 * Allocates temporary memory with default tag.
86 *
87 * Temporary memory blocks are used for not too large memory blocks which
88 * are believed not to stick around for too long. Using this API instead
89 * of RTMemAlloc() not only gives the heap manager room for optimization
90 * but makes the code easier to read.
91 *
92 * @returns Pointer to the allocated memory.
93 * @returns NULL on failure, assertion raised in strict builds.
94 * @param cb Size in bytes of the memory block to allocated.
95 */
96#define RTMemTmpAlloc(cb) RTMemTmpAllocTag((cb), RTMEM_TAG)
97
98/**
99 * Allocates temporary memory with custom tag.
100 *
101 * Temporary memory blocks are used for not too large memory blocks which
102 * are believed not to stick around for too long. Using this API instead
103 * of RTMemAlloc() not only gives the heap manager room for optimization
104 * but makes the code easier to read.
105 *
106 * @returns Pointer to the allocated memory.
107 * @returns NULL on failure, assertion raised in strict builds.
108 * @param cb Size in bytes of the memory block to allocated.
109 * @param pszTag Allocation tag used for statistics and such.
110 */
111RTDECL(void *) RTMemTmpAllocTag(size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
112
113/**
114 * Allocates zero'd temporary memory with default tag.
115 *
116 * Same as RTMemTmpAlloc() but the memory will be zero'd.
117 *
118 * @returns Pointer to the allocated memory.
119 * @returns NULL on failure, assertion raised in strict builds.
120 * @param cb Size in bytes of the memory block to allocated.
121 */
122#define RTMemTmpAllocZ(cb) RTMemTmpAllocZTag((cb), RTMEM_TAG)
123
124/**
125 * Allocates zero'd temporary memory with custom tag.
126 *
127 * Same as RTMemTmpAlloc() but the memory will be zero'd.
128 *
129 * @returns Pointer to the allocated memory.
130 * @returns NULL on failure, assertion raised in strict builds.
131 * @param cb Size in bytes of the memory block to allocated.
132 * @param pszTag Allocation tag used for statistics and such.
133 */
134RTDECL(void *) RTMemTmpAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
135
136/**
137 * Free temporary memory.
138 *
139 * @param pv Pointer to memory block.
140 */
141RTDECL(void) RTMemTmpFree(void *pv) RT_NO_THROW_PROTO;
142
143/** @} */
144
145
146/**
147 * Allocates memory with default tag.
148 *
149 * @returns Pointer to the allocated memory.
150 * @returns NULL on failure, assertion raised in strict builds.
151 * @param cb Size in bytes of the memory block to allocated.
152 */
153#define RTMemAlloc(cb) RTMemAllocTag((cb), RTMEM_TAG)
154
155/**
156 * Allocates memory with custom tag.
157 *
158 * @returns Pointer to the allocated memory.
159 * @returns NULL on failure, assertion raised in strict builds.
160 * @param cb Size in bytes of the memory block to allocated.
161 * @param pszTag Allocation tag used for statistics and such.
162 */
163RTDECL(void *) RTMemAllocTag(size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
164
165/**
166 * Allocates zero'd memory with default tag.
167 *
168 * Instead of memset(pv, 0, sizeof()) use this when you want zero'd
169 * memory. This keeps the code smaller and the heap can skip the memset
170 * in about 0.42% of calls :-).
171 *
172 * @returns Pointer to the allocated memory.
173 * @returns NULL on failure.
174 * @param cb Size in bytes of the memory block to allocated.
175 */
176#define RTMemAllocZ(cb) RTMemAllocZTag((cb), RTMEM_TAG)
177
178/**
179 * Allocates zero'd memory with custom tag.
180 *
181 * Instead of memset(pv, 0, sizeof()) use this when you want zero'd
182 * memory. This keeps the code smaller and the heap can skip the memset
183 * in about 0.42% of calls :-).
184 *
185 * @returns Pointer to the allocated memory.
186 * @returns NULL on failure.
187 * @param cb Size in bytes of the memory block to allocated.
188 * @param pszTag Allocation tag used for statistics and such.
189 */
190RTDECL(void *) RTMemAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
191
192/**
193 * Wrapper around RTMemAlloc for automatically aligning variable sized
194 * allocations so that the various electric fence heaps works correctly.
195 *
196 * @returns See RTMemAlloc.
197 * @param cbUnaligned The unaligned size.
198 */
199#define RTMemAllocVar(cbUnaligned) RTMemAllocVarTag((cbUnaligned), RTMEM_TAG)
200
201/**
202 * Wrapper around RTMemAllocTag for automatically aligning variable sized
203 * allocations so that the various electric fence heaps works correctly.
204 *
205 * @returns See RTMemAlloc.
206 * @param cbUnaligned The unaligned size.
207 * @param pszTag Allocation tag used for statistics and such.
208 */
209RTDECL(void *) RTMemAllocVarTag(size_t cbUnaligned, const char *pszTag) RT_NO_THROW_PROTO;
210
211/**
212 * Wrapper around RTMemAllocZ for automatically aligning variable sized
213 * allocations so that the various electric fence heaps works correctly.
214 *
215 * @returns See RTMemAllocZ.
216 * @param cbUnaligned The unaligned size.
217 */
218#define RTMemAllocZVar(cbUnaligned) RTMemAllocZVarTag((cbUnaligned), RTMEM_TAG)
219
220/**
221 * Wrapper around RTMemAllocZTag for automatically aligning variable sized
222 * allocations so that the various electric fence heaps works correctly.
223 *
224 * @returns See RTMemAllocZ.
225 * @param cbUnaligned The unaligned size.
226 * @param pszTag Allocation tag used for statistics and such.
227 */
228RTDECL(void *) RTMemAllocZVarTag(size_t cbUnaligned, const char *pszTag) RT_NO_THROW_PROTO;
229
230/**
231 * Duplicates a chunk of memory into a new heap block (default tag).
232 *
233 * @returns New heap block with the duplicate data.
234 * @returns NULL if we're out of memory.
235 * @param pvSrc The memory to duplicate.
236 * @param cb The amount of memory to duplicate.
237 */
238#define RTMemDup(pvSrc, cb) RTMemDupTag((pvSrc), (cb), RTMEM_TAG)
239
240/**
241 * Duplicates a chunk of memory into a new heap block (custom tag).
242 *
243 * @returns New heap block with the duplicate data.
244 * @returns NULL if we're out of memory.
245 * @param pvSrc The memory to duplicate.
246 * @param cb The amount of memory to duplicate.
247 * @param pszTag Allocation tag used for statistics and such.
248 */
249RTDECL(void *) RTMemDupTag(const void *pvSrc, size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
250
251/**
252 * Duplicates a chunk of memory into a new heap block with some additional
253 * zeroed memory (default tag).
254 *
255 * @returns New heap block with the duplicate data.
256 * @returns NULL if we're out of memory.
257 * @param pvSrc The memory to duplicate.
258 * @param cbSrc The amount of memory to duplicate.
259 * @param cbExtra The amount of extra memory to allocate and zero.
260 */
261#define RTMemDupEx(pvSrc, cbSrc, cbExtra) RTMemDupExTag((pvSrc), (cbSrc), (cbExtra), RTMEM_TAG)
262
263/**
264 * Duplicates a chunk of memory into a new heap block with some additional
265 * zeroed memory (default tag).
266 *
267 * @returns New heap block with the duplicate data.
268 * @returns NULL if we're out of memory.
269 * @param pvSrc The memory to duplicate.
270 * @param cbSrc The amount of memory to duplicate.
271 * @param cbExtra The amount of extra memory to allocate and zero.
272 * @param pszTag Allocation tag used for statistics and such.
273 */
274RTDECL(void *) RTMemDupExTag(const void *pvSrc, size_t cbSrc, size_t cbExtra, const char *pszTag) RT_NO_THROW_PROTO;
275
276/**
277 * Reallocates memory with default tag.
278 *
279 * @returns Pointer to the allocated memory.
280 * @returns NULL on failure.
281 * @param pvOld The memory block to reallocate.
282 * @param cbNew The new block size (in bytes).
283 */
284#define RTMemRealloc(pvOld, cbNew) RTMemReallocTag((pvOld), (cbNew), RTMEM_TAG)
285
286/**
287 * Reallocates memory with custom tag.
288 *
289 * @returns Pointer to the allocated memory.
290 * @returns NULL on failure.
291 * @param pvOld The memory block to reallocate.
292 * @param cbNew The new block size (in bytes).
293 * @param pszTag Allocation tag used for statistics and such.
294 */
295RTDECL(void *) RTMemReallocTag(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW_PROTO;
296
297/**
298 * Reallocates memory with default tag, initializing any new space to zero.
299 *
300 * @returns Pointer to the allocated memory.
301 * @returns NULL on failure.
302 * @param pvOld The memory block to reallocate.
303 * @param cbOld The old block size (in bytes).
304 * @param cbNew The new block size (in bytes).
305 */
306#define RTMemReallocZ(pvOld, cbOld, cbNew) RTMemReallocZTag((pvOld), (cbOld), (cbNew), RTMEM_TAG)
307
308/**
309 * Reallocates memory with custom tag, initializing any new space to zero.
310 *
311 * @returns Pointer to the allocated memory.
312 * @returns NULL on failure.
313 * @param pvOld The memory block to reallocate.
314 * @param cbOld The old block size (in bytes).
315 * @param cbNew The new block size (in bytes).
316 * @param pszTag Allocation tag used for statistics and such.
317 */
318RTDECL(void *) RTMemReallocZTag(void *pvOld, size_t cbOld, size_t cbNew, const char *pszTag) RT_NO_THROW_PROTO;
319
320/**
321 * Frees memory.
322 *
323 * @param pv Pointer to memory block.
324 */
325RTDECL(void) RTMemFree(void *pv) RT_NO_THROW_PROTO;
326
327
328
329/** @name RTR0MemAllocEx and RTR0MemAllocExTag flags.
330 * @{ */
331/** The returned memory should be zeroed. */
332#define RTMEMALLOCEX_FLAGS_ZEROED RT_BIT(0)
333/** It must be load code into the returned memory block and execute it. */
334#define RTMEMALLOCEX_FLAGS_EXEC RT_BIT(1)
335/** Allocation from any context.
336 * Will return VERR_NOT_SUPPORTED if not supported. */
337#define RTMEMALLOCEX_FLAGS_ANY_CTX_ALLOC RT_BIT(2)
338/** Allocate the memory such that it can be freed from any context.
339 * Will return VERR_NOT_SUPPORTED if not supported. */
340#define RTMEMALLOCEX_FLAGS_ANY_CTX_FREE RT_BIT(3)
341/** Allocate and free from any context.
342 * Will return VERR_NOT_SUPPORTED if not supported. */
343#define RTMEMALLOCEX_FLAGS_ANY_CTX (RTMEMALLOCEX_FLAGS_ANY_CTX_ALLOC | RTMEMALLOCEX_FLAGS_ANY_CTX_FREE)
344/** Reachable by 16-bit address.
345 * Will return VERR_NOT_SUPPORTED if not supported. */
346#define RTMEMALLOCEX_FLAGS_16BIT_REACH RT_BIT(4)
347/** Reachable by 32-bit address.
348 * Will return VERR_NOT_SUPPORTED if not supported. */
349#define RTMEMALLOCEX_FLAGS_32BIT_REACH RT_BIT(5)
350/** Mask of valid flags. */
351#define RTMEMALLOCEX_FLAGS_VALID_MASK UINT32_C(0x0000003f)
352/** Mask of valid flags for ring-0. */
353#define RTMEMALLOCEX_FLAGS_VALID_MASK_R0 UINT32_C(0x0000000f)
354/** @} */
355
356/**
357 * Extended heap allocation API, default tag.
358 *
359 * @returns IPRT status code.
360 * @retval VERR_NO_MEMORY if we're out of memory.
361 * @retval VERR_NO_EXEC_MEMORY if we're out of executable memory.
362 * @retval VERR_NOT_SUPPORTED if any of the specified flags are unsupported.
363 *
364 * @param cb The amount of memory to allocate.
365 * @param cbAlignment The alignment requirements. Use 0 to indicate
366 * default alignment.
367 * @param fFlags A combination of the RTMEMALLOCEX_FLAGS_XXX
368 * defines.
369 * @param ppv Where to return the memory.
370 */
371#define RTMemAllocEx(cb, cbAlignment, fFlags, ppv) RTMemAllocExTag((cb), (cbAlignment), (fFlags), RTMEM_TAG, (ppv))
372
373/**
374 * Extended heap allocation API, custom tag.
375 *
376 * Depending on the implementation, using this function may add extra overhead,
377 * so use the simpler APIs where ever possible.
378 *
379 * @returns IPRT status code.
380 * @retval VERR_NO_MEMORY if we're out of memory.
381 * @retval VERR_NO_EXEC_MEMORY if we're out of executable memory.
382 * @retval VERR_NOT_SUPPORTED if any of the specified flags are unsupported.
383 *
384 * @param cb The amount of memory to allocate.
385 * @param cbAlignment The alignment requirements. Use 0 to indicate
386 * default alignment.
387 * @param fFlags A combination of the RTMEMALLOCEX_FLAGS_XXX
388 * defines.
389 * @param pszTag The tag.
390 * @param ppv Where to return the memory.
391 */
392RTDECL(int) RTMemAllocExTag(size_t cb, size_t cbAlignment, uint32_t fFlags, const char *pszTag, void **ppv) RT_NO_THROW_PROTO;
393
394/**
395 * For freeing memory allocated by RTMemAllocEx or RTMemAllocExTag.
396 *
397 * @param pv What to free, NULL is fine.
398 * @param cb The amount of allocated memory.
399 */
400RTDECL(void) RTMemFreeEx(void *pv, size_t cb) RT_NO_THROW_PROTO;
401
402
403
404/**
405 * Allocates memory which may contain code (default tag).
406 *
407 * @returns Pointer to the allocated memory.
408 * @returns NULL on failure.
409 * @param cb Size in bytes of the memory block to allocate.
410 */
411#define RTMemExecAlloc(cb) RTMemExecAllocTag((cb), RTMEM_TAG)
412
413/**
414 * Allocates memory which may contain code (custom tag).
415 *
416 * @returns Pointer to the allocated memory.
417 * @returns NULL on failure.
418 * @param cb Size in bytes of the memory block to allocate.
419 * @param pszTag Allocation tag used for statistics and such.
420 */
421RTDECL(void *) RTMemExecAllocTag(size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
422
423/**
424 * Free executable/read/write memory allocated by RTMemExecAlloc().
425 *
426 * @param pv Pointer to memory block.
427 * @param cb The allocation size.
428 */
429RTDECL(void) RTMemExecFree(void *pv, size_t cb) RT_NO_THROW_PROTO;
430
431#if defined(IN_RING0) && defined(RT_ARCH_AMD64) && defined(RT_OS_LINUX)
432/**
433 * Donate read+write+execute memory to the exec heap.
434 *
435 * This API is specific to AMD64 and Linux/GNU. A kernel module that desires to
436 * use RTMemExecAlloc on AMD64 Linux/GNU will have to donate some statically
437 * allocated memory in the module if it wishes for GCC generated code to work.
438 * GCC can only generate modules that work in the address range ~2GB to ~0
439 * currently.
440 *
441 * The API only accept one single donation.
442 *
443 * @returns IPRT status code.
444 * @param pvMemory Pointer to the memory block.
445 * @param cb The size of the memory block.
446 */
447RTR0DECL(int) RTR0MemExecDonate(void *pvMemory, size_t cb) RT_NO_THROW_PROTO;
448#endif /* R0+AMD64+LINUX */
449
450/**
451 * Allocate page aligned memory with default tag.
452 *
453 * @returns Pointer to the allocated memory.
454 * @returns NULL if we're out of memory.
455 * @param cb Size of the memory block. Will be rounded up to page size.
456 */
457#define RTMemPageAlloc(cb) RTMemPageAllocTag((cb), RTMEM_TAG)
458
459/**
460 * Allocate page aligned memory with custom tag.
461 *
462 * @returns Pointer to the allocated memory.
463 * @returns NULL if we're out of memory.
464 * @param cb Size of the memory block. Will be rounded up to page size.
465 * @param pszTag Allocation tag used for statistics and such.
466 */
467RTDECL(void *) RTMemPageAllocTag(size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
468
469/**
470 * Allocate zero'd page aligned memory with default tag.
471 *
472 * @returns Pointer to the allocated memory.
473 * @returns NULL if we're out of memory.
474 * @param cb Size of the memory block. Will be rounded up to page size.
475 */
476#define RTMemPageAllocZ(cb) RTMemPageAllocZTag((cb), RTMEM_TAG)
477
478/**
479 * Allocate zero'd page aligned memory with custom tag.
480 *
481 * @returns Pointer to the allocated memory.
482 * @returns NULL if we're out of memory.
483 * @param cb Size of the memory block. Will be rounded up to page size.
484 * @param pszTag Allocation tag used for statistics and such.
485 */
486RTDECL(void *) RTMemPageAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
487
488/**
489 * Allocate page aligned memory with default tag, extended version.
490 *
491 * @returns Pointer to the allocated memory.
492 * @returns NULL if we're out of memory.
493 * @param cb Size of the memory block. Will be rounded up to page size.
494 * @param fFlags RTMEMPAGEALLOC_F_XXX.
495 */
496#define RTMemPageAllocEx(cb, fFlags) RTMemPageAllocExTag((cb), (fFlags), RTMEM_TAG)
497
498/**
499 * Allocate page aligned memory with custom tag, extended version.
500 *
501 * @returns Pointer to the allocated memory.
502 * @returns NULL if we're out of memory.
503 * @param cb Size of the memory block. Will be rounded up to page size.
504 * @param fFlags RTMEMPAGEALLOC_F_XXX.
505 * @param pszTag Allocation tag used for statistics and such.
506 */
507RTDECL(void *) RTMemPageAllocExTag(size_t cb, uint32_t fFlags, const char *pszTag) RT_NO_THROW_PROTO;
508
509/** @name RTMEMPAGEALLOC_F_XXX - flags for RTMemPageAllocEx() and RTMemPageAllocExTag()
510 * @{ */
511/** Zero the allocation. */
512#define RTMEMPAGEALLOC_F_ZERO RT_BIT_32(0)
513/** Try lock the allocation (failure ignored). */
514#define RTMEMPAGEALLOC_F_ADVISE_LOCKED RT_BIT_32(1)
515/** Try prevent the memory from ending up in a dump/core. */
516#define RTMEMPAGEALLOC_F_ADVISE_NO_DUMP RT_BIT_32(2)
517/** Valid bit mask. */
518#define RTMEMPAGEALLOC_F_VALID_MASK UINT32_C(0x00000007)
519/** @} */
520
521/**
522 * Free a memory block allocated with RTMemPageAlloc() or RTMemPageAllocZ().
523 *
524 * @param pv Pointer to the block as it was returned by the allocation function.
525 * NULL will be ignored.
526 * @param cb The allocation size. Will be rounded up to page size.
527 * Ignored if @a pv is NULL.
528 */
529RTDECL(void) RTMemPageFree(void *pv, size_t cb) RT_NO_THROW_PROTO;
530
531/** Page level protection flags for RTMemProtect().
532 * @{
533 */
534/** No access at all. */
535#define RTMEM_PROT_NONE 0
536/** Read access. */
537#define RTMEM_PROT_READ 1
538/** Write access. */
539#define RTMEM_PROT_WRITE 2
540/** Execute access. */
541#define RTMEM_PROT_EXEC 4
542/** @} */
543
544/**
545 * Change the page level protection of a memory region.
546 *
547 * @returns iprt status code.
548 * @param pv Start of the region. Will be rounded down to nearest page boundary.
549 * @param cb Size of the region. Will be rounded up to the nearest page boundary.
550 * @param fProtect The new protection, a combination of the RTMEM_PROT_* defines.
551 */
552RTDECL(int) RTMemProtect(void *pv, size_t cb, unsigned fProtect) RT_NO_THROW_PROTO;
553
554/**
555 * Goes thru some pains to make sure the specified memory block is thoroughly
556 * scrambled.
557 *
558 * @param pv The start of the memory block.
559 * @param cb The size of the memory block.
560 * @param cMinPasses The minimum number of passes to make.
561 */
562RTDECL(void) RTMemWipeThoroughly(void *pv, size_t cb, size_t cMinPasses) RT_NO_THROW_PROTO;
563
564
565/** @def RTMEM_WILL_LEAK
566 * Macro for hinting that a memory allocation @a a_pv will leak.
567 *
568 * @note This shall only be used in code that doesn't allocate the object.
569 * Code allocating memory knowing it will leak shall start the allocation
570 * tag string with 'will-leak:'.
571 */
572/** @def RTMEM_MAY_LEAK
573 * Macro for hinting that a memory allocation @a a_pv may leak.
574 *
575 * @note This shall only be used in code that doesn't allocate the object.
576 * Code allocating memory knowing it may leak shall start the allocation
577 * tag string with 'may-leak:'.
578 */
579#ifdef IPRT_WITH_GCC_SANITIZER
580# define RTMEM_WILL_LEAK(a_pv) __lsan_ignore_object(a_pv)
581# define RTMEM_MAY_LEAK(a_pv) __lsan_ignore_object(a_pv)
582#else
583# define RTMEM_WILL_LEAK(a_pv) do { } while (0)
584# define RTMEM_MAY_LEAK(a_pv) do { } while (0)
585#endif
586
587
588/** @def RTMEM_IMPLEMENT_NEW_AND_DELETE
589 * Provides a new and delete implementation to a class using IPRT's RTMem
590 * allocator.
591 */
592#if !defined(RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF) || defined(RTMEM_NO_WRAP_SOME_NEW_AND_DELETE_TO_EF)
593# ifdef RT_EXCEPTIONS_ENABLED
594# define RTMEM_IMPLEMENT_NEW_AND_DELETE() \
595 void *operator new(size_t cb) RT_THROW(std::bad_alloc) \
596 { \
597 void *pv = RTMemAlloc(cb); \
598 if (RT_LIKELY(pv)) \
599 return pv; \
600 throw std::bad_alloc(); \
601 } \
602 void *operator new(size_t cb, const std::nothrow_t &nothrow_constant) RT_NO_THROW_DEF \
603 { \
604 NOREF(nothrow_constant); \
605 return RTMemAlloc(cb); \
606 } \
607 void *operator new(size_t cb, void *pvBuf) RT_NO_THROW_DEF \
608 { \
609 NOREF(cb); \
610 return pvBuf; \
611 } \
612 void *operator new[](size_t cb) RT_THROW(std::bad_alloc) \
613 { \
614 void *pv = RTMemAlloc(cb); \
615 if (RT_LIKELY(pv)) \
616 return pv; \
617 throw std::bad_alloc(); \
618 } \
619 void *operator new[](size_t cb, const std::nothrow_t &nothrow_constant) RT_NO_THROW_DEF \
620 { \
621 NOREF(nothrow_constant); \
622 return RTMemAlloc(cb); \
623 } \
624 \
625 void operator delete(void *pv) RT_NO_THROW_DEF \
626 { \
627 RTMemFree(pv); \
628 } \
629 void operator delete(void *pv, const std::nothrow_t &nothrow_constant) RT_NO_THROW_DEF \
630 { \
631 NOREF(nothrow_constant); \
632 RTMemFree(pv); \
633 } \
634 void operator delete[](void *pv) RT_NO_THROW_DEF \
635 { \
636 RTMemFree(pv); \
637 } \
638 void operator delete[](void *pv, const std::nothrow_t &nothrow_constant) RT_NO_THROW_DEF \
639 { \
640 NOREF(nothrow_constant); \
641 RTMemFree(pv); \
642 } \
643 \
644 typedef int UsingIprtNewAndDeleteOperators
645# else /* !RT_EXCEPTIONS_ENABLED */
646# define RTMEM_IMPLEMENT_NEW_AND_DELETE() \
647 void *operator new(size_t cb) \
648 { \
649 return RTMemAlloc(cb); \
650 } \
651 void *operator new(size_t cb, const std::nothrow_t &nothrow_constant) \
652 { \
653 NOREF(nothrow_constant); \
654 return RTMemAlloc(cb); \
655 } \
656 void *operator new(size_t cb, void *pvBuf) RT_NO_THROW_DEF \
657 { \
658 NOREF(cb); \
659 return pvBuf; \
660 } \
661 void *operator new[](size_t cb) \
662 { \
663 return RTMemAlloc(cb); \
664 } \
665 void *operator new[](size_t cb, const std::nothrow_t &nothrow_constant) \
666 { \
667 NOREF(nothrow_constant); \
668 return RTMemAlloc(cb); \
669 } \
670 \
671 void operator delete(void *pv) \
672 { \
673 RTMemFree(pv); \
674 } \
675 void operator delete(void *pv, const std::nothrow_t &nothrow_constant) \
676 { \
677 NOREF(nothrow_constant); \
678 RTMemFree(pv); \
679 } \
680 void operator delete[](void *pv) \
681 { \
682 RTMemFree(pv); \
683 } \
684 void operator delete[](void *pv, const std::nothrow_t &nothrow_constant) \
685 { \
686 NOREF(nothrow_constant); \
687 RTMemFree(pv); \
688 } \
689 \
690 typedef int UsingIprtNewAndDeleteOperators
691# endif /* !RT_EXCEPTIONS_ENABLED */
692#else /* defined(RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF) && !defined(RTMEM_NO_WRAP_SOME_NEW_AND_DELETE_TO_EF) */
693# define RTMEM_IMPLEMENT_NEW_AND_DELETE() RTMEMEF_NEW_AND_DELETE_OPERATORS()
694#endif /* defined(RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF) && !defined(RTMEM_NO_WRAP_SOME_NEW_AND_DELETE_TO_EF) */
695
696
697#ifdef IN_RING0
698
699/**
700 * Allocates physical contiguous memory (below 4GB).
701 * The allocation is page aligned and the content is undefined.
702 *
703 * @returns Pointer to the memory block. This is page aligned.
704 * @param pPhys Where to store the physical address.
705 * @param cb The allocation size in bytes. This is always
706 * rounded up to PAGE_SIZE.
707 */
708RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb) RT_NO_THROW_PROTO;
709
710/**
711 * Frees memory allocated ysing RTMemContAlloc().
712 *
713 * @param pv Pointer to return from RTMemContAlloc().
714 * @param cb The cb parameter passed to RTMemContAlloc().
715 */
716RTR0DECL(void) RTMemContFree(void *pv, size_t cb) RT_NO_THROW_PROTO;
717
718/**
719 * Copy memory from an user mode buffer into a kernel buffer.
720 *
721 * @retval VINF_SUCCESS on success.
722 * @retval VERR_ACCESS_DENIED on error.
723 *
724 * @param pvDst The kernel mode destination address.
725 * @param R3PtrSrc The user mode source address.
726 * @param cb The number of bytes to copy.
727 */
728RTR0DECL(int) RTR0MemUserCopyFrom(void *pvDst, RTR3PTR R3PtrSrc, size_t cb);
729
730/**
731 * Copy memory from a kernel buffer into a user mode one.
732 *
733 * @retval VINF_SUCCESS on success.
734 * @retval VERR_ACCESS_DENIED on error.
735 *
736 * @param R3PtrDst The user mode destination address.
737 * @param pvSrc The kernel mode source address.
738 * @param cb The number of bytes to copy.
739 */
740RTR0DECL(int) RTR0MemUserCopyTo(RTR3PTR R3PtrDst, void const *pvSrc, size_t cb);
741
742/**
743 * Tests if the specified address is in the user addressable range.
744 *
745 * This function does not check whether the memory at that address is accessible
746 * or anything of that sort, only if the address it self is in the user mode
747 * range.
748 *
749 * @returns true if it's in the user addressable range. false if not.
750 * @param R3Ptr The user mode pointer to test.
751 *
752 * @remarks Some systems may have overlapping kernel and user address ranges.
753 * One prominent example of this is the x86 version of Mac OS X. Use
754 * RTR0MemAreKrnlAndUsrDifferent() to check.
755 */
756RTR0DECL(bool) RTR0MemUserIsValidAddr(RTR3PTR R3Ptr);
757
758/**
759 * Tests if the specified address is in the kernel mode range.
760 *
761 * This function does not check whether the memory at that address is accessible
762 * or anything of that sort, only if the address it self is in the kernel mode
763 * range.
764 *
765 * @returns true if it's in the kernel range. false if not.
766 * @param pv The alleged kernel mode pointer.
767 *
768 * @remarks Some systems may have overlapping kernel and user address ranges.
769 * One prominent example of this is the x86 version of Mac OS X. Use
770 * RTR0MemAreKrnlAndUsrDifferent() to check.
771 */
772RTR0DECL(bool) RTR0MemKernelIsValidAddr(void *pv);
773
774/**
775 * Are user mode and kernel mode address ranges distinctly different.
776 *
777 * This determines whether RTR0MemKernelIsValidAddr and RTR0MemUserIsValidAddr
778 * can be used for deciding whether some arbitrary address is a user mode or a
779 * kernel mode one.
780 *
781 * @returns true if they are, false if not.
782 */
783RTR0DECL(bool) RTR0MemAreKrnlAndUsrDifferent(void);
784
785/**
786 * Copy memory from an potentially unsafe kernel mode location and into a safe
787 * (kernel) buffer.
788 *
789 * @retval VINF_SUCCESS on success.
790 * @retval VERR_ACCESS_DENIED on error.
791 * @retval VERR_NOT_SUPPORTED if not (yet) supported.
792 *
793 * @param pvDst The destination address (safe).
794 * @param pvSrc The source address (potentially unsafe).
795 * @param cb The number of bytes to copy.
796 */
797RTR0DECL(int) RTR0MemKernelCopyFrom(void *pvDst, void const *pvSrc, size_t cb);
798
799/**
800 * Copy from a safe (kernel) buffer and to a potentially unsafe kenrel mode
801 * location.
802 *
803 * @retval VINF_SUCCESS on success.
804 * @retval VERR_ACCESS_DENIED on error.
805 * @retval VERR_NOT_SUPPORTED if not (yet) supported.
806 *
807 * @param pvDst The destination address (potentially unsafe).
808 * @param pvSrc The source address (safe).
809 * @param cb The number of bytes to copy.
810 */
811RTR0DECL(int) RTR0MemKernelCopyTo(void *pvDst, void const *pvSrc, size_t cb);
812
813#endif /* IN_RING0 */
814
815
816/** @name Electrical Fence Version of some APIs.
817 * @{
818 */
819
820/**
821 * Same as RTMemTmpAllocTag() except that it's fenced.
822 *
823 * @returns Pointer to the allocated memory.
824 * @returns NULL on failure.
825 * @param cb Size in bytes of the memory block to allocate.
826 * @param pszTag Allocation tag used for statistics and such.
827 * @param SRC_POS The source position where call is being made from.
828 * Use RT_SRC_POS when possible. Optional.
829 */
830RTDECL(void *) RTMemEfTmpAlloc(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
831
832/**
833 * Same as RTMemTmpAllocZTag() except that it's fenced.
834 *
835 * @returns Pointer to the allocated memory.
836 * @returns NULL on failure.
837 * @param cb Size in bytes of the memory block to allocate.
838 * @param pszTag Allocation tag used for statistics and such.
839 * @param SRC_POS The source position where call is being made from. Use
840 * RT_SRC_POS when possible. Optional.
841 */
842RTDECL(void *) RTMemEfTmpAllocZ(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
843
844/**
845 * Same as RTMemTmpFree() except that it's for fenced memory.
846 *
847 * @param pv Pointer to memory block.
848 * @param SRC_POS The source position where call is being made from. Use
849 * RT_SRC_POS when possible. Optional.
850 */
851RTDECL(void) RTMemEfTmpFree(void *pv, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
852
853/**
854 * Same as RTMemAllocTag() except that it's fenced.
855 *
856 * @returns Pointer to the allocated memory. Free with RTMemEfFree().
857 * @returns NULL on failure.
858 * @param cb Size in bytes of the memory block to allocate.
859 * @param pszTag Allocation tag used for statistics and such.
860 * @param SRC_POS The source position where call is being made from. Use
861 * RT_SRC_POS when possible. Optional.
862 */
863RTDECL(void *) RTMemEfAlloc(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
864
865/**
866 * Same as RTMemAllocZTag() except that it's fenced.
867 *
868 * @returns Pointer to the allocated memory.
869 * @returns NULL on failure.
870 * @param cb Size in bytes of the memory block to allocate.
871 * @param pszTag Allocation tag used for statistics and such.
872 * @param SRC_POS The source position where call is being made from. Use
873 * RT_SRC_POS when possible. Optional.
874 */
875RTDECL(void *) RTMemEfAllocZ(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
876
877/**
878 * Same as RTMemAllocVarTag() except that it's fenced.
879 *
880 * @returns Pointer to the allocated memory. Free with RTMemEfFree().
881 * @returns NULL on failure.
882 * @param cbUnaligned Size in bytes of the memory block to allocate.
883 * @param pszTag Allocation tag used for statistics and such.
884 * @param SRC_POS The source position where call is being made from. Use
885 * RT_SRC_POS when possible. Optional.
886 */
887RTDECL(void *) RTMemEfAllocVar(size_t cbUnaligned, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
888
889/**
890 * Same as RTMemAllocZVarTag() except that it's fenced.
891 *
892 * @returns Pointer to the allocated memory.
893 * @returns NULL on failure.
894 * @param cbUnaligned Size in bytes of the memory block to allocate.
895 * @param pszTag Allocation tag used for statistics and such.
896 * @param SRC_POS The source position where call is being made from. Use
897 * RT_SRC_POS when possible. Optional.
898 */
899RTDECL(void *) RTMemEfAllocZVar(size_t cbUnaligned, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
900
901/**
902 * Same as RTMemReallocTag() except that it's fenced.
903 *
904 * @returns Pointer to the allocated memory.
905 * @returns NULL on failure.
906 * @param pvOld The memory block to reallocate.
907 * @param cbNew The new block size (in bytes).
908 * @param pszTag Allocation tag used for statistics and such.
909 * @param SRC_POS The source position where call is being made from. Use
910 * RT_SRC_POS when possible. Optional.
911 */
912RTDECL(void *) RTMemEfRealloc(void *pvOld, size_t cbNew, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
913
914/**
915 * Same as RTMemReallocZTag() except that it's fenced.
916 *
917 * @returns Pointer to the allocated memory.
918 * @returns NULL on failure.
919 * @param pvOld The memory block to reallocate.
920 * @param cbOld The old block size (in bytes).
921 * @param cbNew The new block size (in bytes).
922 * @param pszTag Allocation tag used for statistics and such.
923 * @param SRC_POS The source position where call is being made from. Use
924 * RT_SRC_POS when possible. Optional.
925 */
926RTDECL(void *) RTMemEfReallocZ(void *pvOld, size_t cbOld, size_t cbNew, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
927
928/**
929 * Free memory allocated by any of the RTMemEf* allocators.
930 *
931 * @param pv Pointer to memory block.
932 * @param SRC_POS The source position where call is being made from. Use
933 * RT_SRC_POS when possible. Optional.
934 */
935RTDECL(void) RTMemEfFree(void *pv, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
936
937/**
938 * Same as RTMemDupTag() except that it's fenced.
939 *
940 * @returns New heap block with the duplicate data.
941 * @returns NULL if we're out of memory.
942 * @param pvSrc The memory to duplicate.
943 * @param cb The amount of memory to duplicate.
944 * @param pszTag Allocation tag used for statistics and such.
945 * @param SRC_POS The source position where call is being made from. Use
946 * RT_SRC_POS when possible. Optional.
947 */
948RTDECL(void *) RTMemEfDup(const void *pvSrc, size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
949
950/**
951 * Same as RTMemEfDupExTag except that it's fenced.
952 *
953 * @returns New heap block with the duplicate data.
954 * @returns NULL if we're out of memory.
955 * @param pvSrc The memory to duplicate.
956 * @param cbSrc The amount of memory to duplicate.
957 * @param cbExtra The amount of extra memory to allocate and zero.
958 * @param pszTag Allocation tag used for statistics and such.
959 * @param SRC_POS The source position where call is being made from. Use
960 * RT_SRC_POS when possible. Optional.
961 */
962RTDECL(void *) RTMemEfDupEx(const void *pvSrc, size_t cbSrc, size_t cbExtra, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
963
964/** @def RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF
965 * Define RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF to enable electric fence new and
966 * delete operators for classes which uses the RTMEMEF_NEW_AND_DELETE_OPERATORS
967 * macro.
968 */
969/** @def RTMEMEF_NEW_AND_DELETE_OPERATORS
970 * Defines the electric fence new and delete operators for a class when
971 * RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF is define.
972 */
973/** @def RTR0MEMEF_NEW_AND_DELETE_OPERATORS_IOKIT
974 * Defines the electric fence new and delete operators for an IOKit class when
975 * RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF is define.
976 *
977 * This differs from RTMEMEF_NEW_AND_DELETE_OPERATORS in that the memory we
978 * allocate is initialized to zero. It is also assuming we don't have nothrow
979 * variants and exceptions, so fewer variations.
980 */
981#if defined(RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF) && !defined(RTMEM_NO_WRAP_SOME_NEW_AND_DELETE_TO_EF)
982# if defined(RT_EXCEPTIONS_ENABLED)
983# define RTMEMEF_NEW_AND_DELETE_OPERATORS() \
984 void *operator new(size_t cb) RT_THROW(std::bad_alloc) \
985 { \
986 void *pv = RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
987 if (RT_LIKELY(pv)) \
988 return pv; \
989 throw std::bad_alloc(); \
990 } \
991 void *operator new(size_t cb, const std::nothrow_t &nothrow_constant) RT_NO_THROW_DEF \
992 { \
993 NOREF(nothrow_constant); \
994 return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
995 } \
996 void *operator new(size_t cb, void *pvBuf) RT_NO_THROW_DEF \
997 { \
998 NOREF(cb); \
999 return pvBuf; \
1000 } \
1001 void *operator new[](size_t cb) RT_THROW(std::bad_alloc) \
1002 { \
1003 void *pv = RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
1004 if (RT_LIKELY(pv)) \
1005 return pv; \
1006 throw std::bad_alloc(); \
1007 } \
1008 void *operator new[](size_t cb, const std::nothrow_t &nothrow_constant) RT_NO_THROW_DEF \
1009 { \
1010 NOREF(nothrow_constant); \
1011 return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
1012 } \
1013 \
1014 void operator delete(void *pv) RT_NO_THROW_DEF \
1015 { \
1016 RTMemEfFree(pv, RT_SRC_POS); \
1017 } \
1018 void operator delete(void *pv, const std::nothrow_t &nothrow_constant) RT_NO_THROW_DEF \
1019 { \
1020 NOREF(nothrow_constant); \
1021 RTMemEfFree(pv, RT_SRC_POS); \
1022 } \
1023 void operator delete[](void *pv) RT_NO_THROW_DEF \
1024 { \
1025 RTMemEfFree(pv, RT_SRC_POS); \
1026 } \
1027 void operator delete[](void *pv, const std::nothrow_t &nothrow_constant) RT_NO_THROW_DEF \
1028 { \
1029 NOREF(nothrow_constant); \
1030 RTMemEfFree(pv, RT_SRC_POS); \
1031 } \
1032 \
1033 typedef int UsingElectricNewAndDeleteOperators
1034# else
1035# define RTMEMEF_NEW_AND_DELETE_OPERATORS() \
1036 void *operator new(size_t cb) \
1037 { \
1038 return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
1039 } \
1040 void *operator new(size_t cb, const std::nothrow_t &nothrow_constant) \
1041 { \
1042 NOREF(nothrow_constant); \
1043 return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
1044 } \
1045 void *operator new(size_t cb, void *pvBuf) RT_NO_THROW_DEF \
1046 { \
1047 NOREF(cb); \
1048 return pvBuf; \
1049 } \
1050 void *operator new[](size_t cb) \
1051 { \
1052 return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
1053 } \
1054 void *operator new[](size_t cb, const std::nothrow_t &nothrow_constant) \
1055 { \
1056 NOREF(nothrow_constant); \
1057 return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
1058 } \
1059 \
1060 void operator delete(void *pv) \
1061 { \
1062 RTMemEfFree(pv, RT_SRC_POS); \
1063 } \
1064 void operator delete(void *pv, const std::nothrow_t &nothrow_constant) \
1065 { \
1066 NOREF(nothrow_constant); \
1067 RTMemEfFree(pv, RT_SRC_POS); \
1068 } \
1069 void operator delete[](void *pv) \
1070 { \
1071 RTMemEfFree(pv, RT_SRC_POS); \
1072 } \
1073 void operator delete[](void *pv, const std::nothrow_t &nothrow_constant) \
1074 { \
1075 NOREF(nothrow_constant); \
1076 RTMemEfFree(pv, RT_SRC_POS); \
1077 } \
1078 \
1079 typedef int UsingElectricNewAndDeleteOperators
1080# endif
1081# define RTR0MEMEF_NEW_AND_DELETE_OPERATORS_IOKIT() \
1082 void *operator new(size_t cb) \
1083 { \
1084 return RTMemEfAllocZ(cb, RTMEM_TAG, RT_SRC_POS); \
1085 } \
1086 void *operator new[](size_t cb) \
1087 { \
1088 return RTMemEfAllocZ(cb, RTMEM_TAG, RT_SRC_POS); \
1089 } \
1090 \
1091 void operator delete(void *pv) \
1092 { \
1093 RTMemEfFree(pv, RT_SRC_POS); \
1094 } \
1095 void operator delete[](void *pv) \
1096 { \
1097 RTMemEfFree(pv, RT_SRC_POS); \
1098 } \
1099 \
1100 typedef int UsingElectricNewAndDeleteOperators
1101#else
1102# define RTMEMEF_NEW_AND_DELETE_OPERATORS() \
1103 typedef int UsingDefaultNewAndDeleteOperators
1104# define RTR0MEMEF_NEW_AND_DELETE_OPERATORS_IOKIT() \
1105 typedef int UsingDefaultNewAndDeleteOperators
1106#endif
1107#ifdef DOXYGEN_RUNNING
1108# define RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF
1109#endif
1110
1111/** @def RTMEM_WRAP_TO_EF_APIS
1112 * Define RTMEM_WRAP_TO_EF_APIS to wrap RTMem APIs to RTMemEf APIs.
1113 */
1114#if defined(RTMEM_WRAP_TO_EF_APIS) && !defined(RTMEM_NO_WRAP_TO_EF_APIS) \
1115 && ( defined(IN_RING3) || ( defined(IN_RING0) && !defined(IN_RING0_AGNOSTIC) && (defined(RT_OS_DARWIN) || 0) ) )
1116# define RTMemTmpAllocTag(cb, pszTag) RTMemEfTmpAlloc((cb), (pszTag), RT_SRC_POS)
1117# define RTMemTmpAllocZTag(cb, pszTag) RTMemEfTmpAllocZ((cb), (pszTag), RT_SRC_POS)
1118# define RTMemTmpFree(pv) RTMemEfTmpFree((pv), RT_SRC_POS)
1119# define RTMemAllocTag(cb, pszTag) RTMemEfAlloc((cb), (pszTag), RT_SRC_POS)
1120# define RTMemAllocZTag(cb, pszTag) RTMemEfAllocZ((cb), (pszTag), RT_SRC_POS)
1121# define RTMemAllocVarTag(cbUnaligned, pszTag) RTMemEfAllocVar((cbUnaligned), (pszTag), RT_SRC_POS)
1122# define RTMemAllocZVarTag(cbUnaligned, pszTag) RTMemEfAllocZVar((cbUnaligned), (pszTag), RT_SRC_POS)
1123# define RTMemReallocTag(pvOld, cbNew, pszTag) RTMemEfRealloc((pvOld), (cbNew), (pszTag), RT_SRC_POS)
1124# define RTMemReallocZTag(pvOld, cbOld, cbNew, pszTag) RTMemEfReallocZ((pvOld), (cbOld), (cbNew), (pszTag), RT_SRC_POS)
1125# define RTMemFree(pv) RTMemEfFree((pv), RT_SRC_POS)
1126# define RTMemDupTag(pvSrc, cb, pszTag) RTMemEfDup((pvSrc), (cb), (pszTag), RT_SRC_POS)
1127# define RTMemDupExTag(pvSrc, cbSrc, cbExtra, pszTag) RTMemEfDupEx((pvSrc), (cbSrc), (cbExtra), (pszTag), RT_SRC_POS)
1128#endif
1129#ifdef DOXYGEN_RUNNING
1130# define RTMEM_WRAP_TO_EF_APIS
1131#endif
1132
1133/**
1134 * Fenced drop-in replacement for RTMemTmpAllocTag.
1135 * @copydoc RTMemTmpAllocTag
1136 */
1137RTDECL(void *) RTMemEfTmpAllocNP(size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
1138
1139/**
1140 * Fenced drop-in replacement for RTMemTmpAllocZTag.
1141 * @copydoc RTMemTmpAllocZTag
1142 */
1143RTDECL(void *) RTMemEfTmpAllocZNP(size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
1144
1145/**
1146 * Fenced drop-in replacement for RTMemTmpFreeTag.
1147 * @copydoc RTMemTmpFree
1148 */
1149RTDECL(void) RTMemEfTmpFreeNP(void *pv) RT_NO_THROW_PROTO;
1150
1151/**
1152 * Fenced drop-in replacement for RTMemAllocTag.
1153 * @copydoc RTMemAllocTag
1154 */
1155RTDECL(void *) RTMemEfAllocNP(size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
1156
1157/**
1158 * Fenced drop-in replacement for RTMemAllocZTag.
1159 * @copydoc RTMemAllocZTag
1160 */
1161RTDECL(void *) RTMemEfAllocZNP(size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
1162
1163/**
1164 * Fenced drop-in replacement for RTMemAllocVarTag
1165 * @copydoc RTMemAllocVarTag
1166 */
1167RTDECL(void *) RTMemEfAllocVarNP(size_t cbUnaligned, const char *pszTag) RT_NO_THROW_PROTO;
1168
1169/**
1170 * Fenced drop-in replacement for RTMemAllocZVarTag.
1171 * @copydoc RTMemAllocZVarTag
1172 */
1173RTDECL(void *) RTMemEfAllocZVarNP(size_t cbUnaligned, const char *pszTag) RT_NO_THROW_PROTO;
1174
1175/**
1176 * Fenced drop-in replacement for RTMemReallocTag.
1177 * @copydoc RTMemReallocTag
1178 */
1179RTDECL(void *) RTMemEfReallocNP(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW_PROTO;
1180
1181/**
1182 * Fenced drop-in replacement for RTMemReallocZTag.
1183 * @copydoc RTMemReallocZTag
1184 */
1185RTDECL(void *) RTMemEfReallocZNP(void *pvOld, size_t cbOld, size_t cbNew, const char *pszTag) RT_NO_THROW_PROTO;
1186
1187/**
1188 * Fenced drop-in replacement for RTMemFree.
1189 * @copydoc RTMemFree
1190 */
1191RTDECL(void) RTMemEfFreeNP(void *pv) RT_NO_THROW_PROTO;
1192
1193/**
1194 * Fenced drop-in replacement for RTMemDupExTag.
1195 * @copydoc RTMemDupTag
1196 */
1197RTDECL(void *) RTMemEfDupNP(const void *pvSrc, size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
1198
1199/**
1200 * Fenced drop-in replacement for RTMemDupExTag.
1201 * @copydoc RTMemDupExTag
1202 */
1203RTDECL(void *) RTMemEfDupExNP(const void *pvSrc, size_t cbSrc, size_t cbExtra, const char *pszTag) RT_NO_THROW_PROTO;
1204
1205/** @} */
1206
1207RT_C_DECLS_END
1208
1209/** @} */
1210
1211
1212#endif /* !IPRT_INCLUDED_mem_h */
1213
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette