VirtualBox

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

Last change on this file since 98263 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

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