VirtualBox

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

Last change on this file since 106430 was 106061, checked in by vboxsync, 3 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.5 KB
Line 
1/** @file
2 * IPRT - Memory Management and Manipulation.
3 */
4
5/*
6 * Copyright (C) 2006-2024 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/** Allocate pages that are readable, writeable and executable.
510 * @note This may fail on some platforms for security policy reasons. */
511#define RTMEMPAGEALLOC_F_EXECUTABLE RT_BIT_32(3)
512/** Valid bit mask. */
513#define RTMEMPAGEALLOC_F_VALID_MASK UINT32_C(0x0000000f)
514/** @} */
515
516/**
517 * Free a memory block allocated with RTMemPageAlloc() or RTMemPageAllocZ().
518 *
519 * @param pv Pointer to the block as it was returned by the allocation function.
520 * NULL will be ignored.
521 * @param cb The allocation size. Will be rounded up to page size.
522 * Ignored if @a pv is NULL.
523 */
524RTDECL(void) RTMemPageFree(void *pv, size_t cb) RT_NO_THROW_PROTO;
525
526/** Page level protection flags for RTMemProtect().
527 * @{
528 */
529/** No access at all. */
530#define RTMEM_PROT_NONE 0
531/** Read access. */
532#define RTMEM_PROT_READ 1
533/** Write access. */
534#define RTMEM_PROT_WRITE 2
535/** Execute access. */
536#define RTMEM_PROT_EXEC 4
537/** @} */
538
539/**
540 * Change the page level protection of a memory region.
541 *
542 * @returns iprt status code.
543 * @param pv Start of the region. Will be rounded down to nearest page boundary.
544 * @param cb Size of the region. Will be rounded up to the nearest page boundary.
545 * @param fProtect The new protection, a combination of the RTMEM_PROT_* defines.
546 */
547RTDECL(int) RTMemProtect(void *pv, size_t cb, unsigned fProtect) RT_NO_THROW_PROTO;
548
549/**
550 * Goes thru some pains to make sure the specified memory block is thoroughly
551 * scrambled.
552 *
553 * @param pv The start of the memory block.
554 * @param cb The size of the memory block.
555 * @param cMinPasses The minimum number of passes to make.
556 */
557RTDECL(void) RTMemWipeThoroughly(void *pv, size_t cb, size_t cMinPasses) RT_NO_THROW_PROTO;
558
559
560/** @def RTMEM_WILL_LEAK
561 * Macro for hinting that a memory allocation @a a_pv will leak.
562 *
563 * @note This shall only be used in code that doesn't allocate the object.
564 * Code allocating memory knowing it will leak shall start the allocation
565 * tag string with 'will-leak:'.
566 */
567/** @def RTMEM_MAY_LEAK
568 * Macro for hinting that a memory allocation @a a_pv may leak.
569 *
570 * @note This shall only be used in code that doesn't allocate the object.
571 * Code allocating memory knowing it may leak shall start the allocation
572 * tag string with 'may-leak:'.
573 */
574#ifdef IPRT_WITH_GCC_SANITIZER
575# define RTMEM_WILL_LEAK(a_pv) __lsan_ignore_object(a_pv)
576# define RTMEM_MAY_LEAK(a_pv) __lsan_ignore_object(a_pv)
577#else
578# define RTMEM_WILL_LEAK(a_pv) do { } while (0)
579# define RTMEM_MAY_LEAK(a_pv) do { } while (0)
580#endif
581
582
583/** @def RTMEM_IMPLEMENT_NEW_AND_DELETE
584 * Provides a new and delete implementation to a class using IPRT's RTMem
585 * allocator.
586 */
587#if !defined(RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF) || defined(RTMEM_NO_WRAP_SOME_NEW_AND_DELETE_TO_EF)
588# ifdef RT_EXCEPTIONS_ENABLED
589# define RTMEM_IMPLEMENT_NEW_AND_DELETE() \
590 void *operator new(size_t cb) RT_THROW(std::bad_alloc) \
591 { \
592 void *pv = RTMemAlloc(cb); \
593 if (RT_LIKELY(pv)) \
594 return pv; \
595 throw std::bad_alloc(); \
596 } \
597 void *operator new(size_t cb, const std::nothrow_t &nothrow_constant) RT_NO_THROW_DEF \
598 { \
599 NOREF(nothrow_constant); \
600 return RTMemAlloc(cb); \
601 } \
602 void *operator new(size_t cb, void *pvBuf) RT_NO_THROW_DEF \
603 { \
604 NOREF(cb); \
605 return pvBuf; \
606 } \
607 void *operator new[](size_t cb) RT_THROW(std::bad_alloc) \
608 { \
609 void *pv = RTMemAlloc(cb); \
610 if (RT_LIKELY(pv)) \
611 return pv; \
612 throw std::bad_alloc(); \
613 } \
614 void *operator new[](size_t cb, const std::nothrow_t &nothrow_constant) RT_NO_THROW_DEF \
615 { \
616 NOREF(nothrow_constant); \
617 return RTMemAlloc(cb); \
618 } \
619 \
620 void operator delete(void *pv) RT_NO_THROW_DEF \
621 { \
622 RTMemFree(pv); \
623 } \
624 void operator delete(void *pv, const std::nothrow_t &nothrow_constant) RT_NO_THROW_DEF \
625 { \
626 NOREF(nothrow_constant); \
627 RTMemFree(pv); \
628 } \
629 void operator delete[](void *pv) RT_NO_THROW_DEF \
630 { \
631 RTMemFree(pv); \
632 } \
633 void operator delete[](void *pv, const std::nothrow_t &nothrow_constant) RT_NO_THROW_DEF \
634 { \
635 NOREF(nothrow_constant); \
636 RTMemFree(pv); \
637 } \
638 \
639 typedef int UsingIprtNewAndDeleteOperators
640# else /* !RT_EXCEPTIONS_ENABLED */
641# define RTMEM_IMPLEMENT_NEW_AND_DELETE() \
642 void *operator new(size_t cb) \
643 { \
644 return RTMemAlloc(cb); \
645 } \
646 void *operator new(size_t cb, const std::nothrow_t &nothrow_constant) \
647 { \
648 NOREF(nothrow_constant); \
649 return RTMemAlloc(cb); \
650 } \
651 void *operator new(size_t cb, void *pvBuf) RT_NO_THROW_DEF \
652 { \
653 NOREF(cb); \
654 return pvBuf; \
655 } \
656 void *operator new[](size_t cb) \
657 { \
658 return RTMemAlloc(cb); \
659 } \
660 void *operator new[](size_t cb, const std::nothrow_t &nothrow_constant) \
661 { \
662 NOREF(nothrow_constant); \
663 return RTMemAlloc(cb); \
664 } \
665 \
666 void operator delete(void *pv) \
667 { \
668 RTMemFree(pv); \
669 } \
670 void operator delete(void *pv, const std::nothrow_t &nothrow_constant) \
671 { \
672 NOREF(nothrow_constant); \
673 RTMemFree(pv); \
674 } \
675 void operator delete[](void *pv) \
676 { \
677 RTMemFree(pv); \
678 } \
679 void operator delete[](void *pv, const std::nothrow_t &nothrow_constant) \
680 { \
681 NOREF(nothrow_constant); \
682 RTMemFree(pv); \
683 } \
684 \
685 typedef int UsingIprtNewAndDeleteOperators
686# endif /* !RT_EXCEPTIONS_ENABLED */
687#else /* defined(RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF) && !defined(RTMEM_NO_WRAP_SOME_NEW_AND_DELETE_TO_EF) */
688# define RTMEM_IMPLEMENT_NEW_AND_DELETE() RTMEMEF_NEW_AND_DELETE_OPERATORS()
689#endif /* defined(RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF) && !defined(RTMEM_NO_WRAP_SOME_NEW_AND_DELETE_TO_EF) */
690
691
692#ifdef IN_RING0
693
694/**
695 * Allocates physical contiguous memory (below 4GB).
696 * The allocation is page aligned and the content is undefined.
697 *
698 * @returns Pointer to the memory block. This is page aligned.
699 * @param pPhys Where to store the physical address.
700 * @param cb The allocation size in bytes. This is always
701 * rounded up to PAGE_SIZE.
702 */
703RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb) RT_NO_THROW_PROTO;
704
705/**
706 * Frees memory allocated ysing RTMemContAlloc().
707 *
708 * @param pv Pointer to return from RTMemContAlloc().
709 * @param cb The cb parameter passed to RTMemContAlloc().
710 */
711RTR0DECL(void) RTMemContFree(void *pv, size_t cb) RT_NO_THROW_PROTO;
712
713/**
714 * Copy memory from an user mode buffer into a kernel buffer.
715 *
716 * @retval VINF_SUCCESS on success.
717 * @retval VERR_ACCESS_DENIED on error.
718 *
719 * @param pvDst The kernel mode destination address.
720 * @param R3PtrSrc The user mode source address.
721 * @param cb The number of bytes to copy.
722 */
723RTR0DECL(int) RTR0MemUserCopyFrom(void *pvDst, RTR3PTR R3PtrSrc, size_t cb);
724
725/**
726 * Copy memory from a kernel buffer into a user mode one.
727 *
728 * @retval VINF_SUCCESS on success.
729 * @retval VERR_ACCESS_DENIED on error.
730 *
731 * @param R3PtrDst The user mode destination address.
732 * @param pvSrc The kernel mode source address.
733 * @param cb The number of bytes to copy.
734 */
735RTR0DECL(int) RTR0MemUserCopyTo(RTR3PTR R3PtrDst, void const *pvSrc, size_t cb);
736
737/**
738 * Tests if the specified address is in the user addressable range.
739 *
740 * This function does not check whether the memory at that address is accessible
741 * or anything of that sort, only if the address it self is in the user mode
742 * range.
743 *
744 * @returns true if it's in the user addressable range. false if not.
745 * @param R3Ptr The user mode pointer to test.
746 *
747 * @remarks Some systems may have overlapping kernel and user address ranges.
748 * One prominent example of this is the x86 version of Mac OS X. Use
749 * RTR0MemAreKrnlAndUsrDifferent() to check.
750 */
751RTR0DECL(bool) RTR0MemUserIsValidAddr(RTR3PTR R3Ptr);
752
753/**
754 * Tests if the specified address is in the kernel mode range.
755 *
756 * This function does not check whether the memory at that address is accessible
757 * or anything of that sort, only if the address it self is in the kernel mode
758 * range.
759 *
760 * @returns true if it's in the kernel range. false if not.
761 * @param pv The alleged kernel mode pointer.
762 *
763 * @remarks Some systems may have overlapping kernel and user address ranges.
764 * One prominent example of this is the x86 version of Mac OS X. Use
765 * RTR0MemAreKrnlAndUsrDifferent() to check.
766 */
767RTR0DECL(bool) RTR0MemKernelIsValidAddr(void *pv);
768
769/**
770 * Are user mode and kernel mode address ranges distinctly different.
771 *
772 * This determines whether RTR0MemKernelIsValidAddr and RTR0MemUserIsValidAddr
773 * can be used for deciding whether some arbitrary address is a user mode or a
774 * kernel mode one.
775 *
776 * @returns true if they are, false if not.
777 */
778RTR0DECL(bool) RTR0MemAreKrnlAndUsrDifferent(void);
779
780/**
781 * Copy memory from an potentially unsafe kernel mode location and into a safe
782 * (kernel) buffer.
783 *
784 * @retval VINF_SUCCESS on success.
785 * @retval VERR_ACCESS_DENIED on error.
786 * @retval VERR_NOT_SUPPORTED if not (yet) supported.
787 *
788 * @param pvDst The destination address (safe).
789 * @param pvSrc The source address (potentially unsafe).
790 * @param cb The number of bytes to copy.
791 */
792RTR0DECL(int) RTR0MemKernelCopyFrom(void *pvDst, void const *pvSrc, size_t cb);
793
794/**
795 * Copy from a safe (kernel) buffer and to a potentially unsafe kenrel mode
796 * location.
797 *
798 * @retval VINF_SUCCESS on success.
799 * @retval VERR_ACCESS_DENIED on error.
800 * @retval VERR_NOT_SUPPORTED if not (yet) supported.
801 *
802 * @param pvDst The destination address (potentially unsafe).
803 * @param pvSrc The source address (safe).
804 * @param cb The number of bytes to copy.
805 */
806RTR0DECL(int) RTR0MemKernelCopyTo(void *pvDst, void const *pvSrc, size_t cb);
807
808#endif /* IN_RING0 */
809
810
811/** @name Electrical Fence Version of some APIs.
812 * @{
813 */
814
815/**
816 * Same as RTMemTmpAllocTag() except that it's fenced.
817 *
818 * @returns Pointer to the allocated memory.
819 * @returns NULL on failure.
820 * @param cb Size in bytes of the memory block to allocate.
821 * @param pszTag Allocation tag used for statistics and such.
822 * @param SRC_POS The source position where call is being made from.
823 * Use RT_SRC_POS when possible. Optional.
824 */
825RTDECL(void *) RTMemEfTmpAlloc(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
826
827/**
828 * Same as RTMemTmpAllocZTag() except that it's fenced.
829 *
830 * @returns Pointer to the allocated memory.
831 * @returns NULL on failure.
832 * @param cb Size in bytes of the memory block to allocate.
833 * @param pszTag Allocation tag used for statistics and such.
834 * @param SRC_POS The source position where call is being made from. Use
835 * RT_SRC_POS when possible. Optional.
836 */
837RTDECL(void *) RTMemEfTmpAllocZ(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
838
839/**
840 * Same as RTMemTmpFree() except that it's for fenced memory.
841 *
842 * @param pv Pointer to memory block.
843 * @param SRC_POS The source position where call is being made from. Use
844 * RT_SRC_POS when possible. Optional.
845 */
846RTDECL(void) RTMemEfTmpFree(void *pv, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
847
848/**
849 * Same as RTMemTmpFreeZ() except that it's for fenced memory.
850 *
851 * @param pv Pointer to memory block.
852 * @param cb Size of the memory block.
853 * @param SRC_POS The source position where call is being made from. Use
854 * RT_SRC_POS when possible. Optional.
855 */
856RTDECL(void) RTMemEfTmpFreeZ(void *pv, size_t cb, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
857
858/**
859 * Same as RTMemAllocTag() except that it's fenced.
860 *
861 * @returns Pointer to the allocated memory. Free with RTMemEfFree().
862 * @returns NULL on failure.
863 * @param cb Size in bytes of the memory block to allocate.
864 * @param pszTag Allocation tag used for statistics and such.
865 * @param SRC_POS The source position where call is being made from. Use
866 * RT_SRC_POS when possible. Optional.
867 */
868RTDECL(void *) RTMemEfAlloc(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
869
870/**
871 * Same as RTMemAllocZTag() except that it's fenced.
872 *
873 * @returns Pointer to the allocated memory.
874 * @returns NULL on failure.
875 * @param cb Size in bytes of the memory block to allocate.
876 * @param pszTag Allocation tag used for statistics and such.
877 * @param SRC_POS The source position where call is being made from. Use
878 * RT_SRC_POS when possible. Optional.
879 */
880RTDECL(void *) RTMemEfAllocZ(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
881
882/**
883 * Same as RTMemAllocVarTag() except that it's fenced.
884 *
885 * @returns Pointer to the allocated memory. Free with RTMemEfFree().
886 * @returns NULL on failure.
887 * @param cbUnaligned Size in bytes of the memory block to allocate.
888 * @param pszTag Allocation tag used for statistics and such.
889 * @param SRC_POS The source position where call is being made from. Use
890 * RT_SRC_POS when possible. Optional.
891 */
892RTDECL(void *) RTMemEfAllocVar(size_t cbUnaligned, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
893
894/**
895 * Same as RTMemAllocZVarTag() except that it's fenced.
896 *
897 * @returns Pointer to the allocated memory.
898 * @returns NULL on failure.
899 * @param cbUnaligned Size in bytes of the memory block to allocate.
900 * @param pszTag Allocation tag used for statistics and such.
901 * @param SRC_POS The source position where call is being made from. Use
902 * RT_SRC_POS when possible. Optional.
903 */
904RTDECL(void *) RTMemEfAllocZVar(size_t cbUnaligned, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
905
906/**
907 * Same as RTMemReallocTag() except that it's fenced.
908 *
909 * @returns Pointer to the allocated memory.
910 * @returns NULL on failure.
911 * @param pvOld The memory block to reallocate.
912 * @param cbNew The new block size (in bytes).
913 * @param pszTag Allocation tag used for statistics and such.
914 * @param SRC_POS The source position where call is being made from. Use
915 * RT_SRC_POS when possible. Optional.
916 */
917RTDECL(void *) RTMemEfRealloc(void *pvOld, size_t cbNew, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
918
919/**
920 * Same as RTMemReallocZTag() except that it's fenced.
921 *
922 * @returns Pointer to the allocated memory.
923 * @returns NULL on failure.
924 * @param pvOld The memory block to reallocate.
925 * @param cbOld The old block size (in bytes).
926 * @param cbNew The new block size (in bytes).
927 * @param pszTag Allocation tag used for statistics and such.
928 * @param SRC_POS The source position where call is being made from. Use
929 * RT_SRC_POS when possible. Optional.
930 */
931RTDECL(void *) RTMemEfReallocZ(void *pvOld, size_t cbOld, size_t cbNew, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
932
933/**
934 * Free memory allocated by any of the RTMemEf* allocators.
935 *
936 * @param pv Pointer to memory block.
937 * @param SRC_POS The source position where call is being made from. Use
938 * RT_SRC_POS when possible. Optional.
939 */
940RTDECL(void) RTMemEfFree(void *pv, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
941
942/**
943 * Clear and free memory allocated by any of the RTMemEf* allocators.
944 *
945 * @param pv Pointer to memory block.
946 * @param cb Size of the allocation.
947 * @param SRC_POS The source position where call is being made from. Use
948 * RT_SRC_POS when possible. Optional.
949 */
950RTDECL(void) RTMemEfFreeZ(void *pv, size_t cb, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
951
952/**
953 * Same as RTMemDupTag() except that it's fenced.
954 *
955 * @returns New heap block with the duplicate data.
956 * @returns NULL if we're out of memory.
957 * @param pvSrc The memory to duplicate.
958 * @param cb The amount of memory to duplicate.
959 * @param pszTag Allocation tag used for statistics and such.
960 * @param SRC_POS The source position where call is being made from. Use
961 * RT_SRC_POS when possible. Optional.
962 */
963RTDECL(void *) RTMemEfDup(const void *pvSrc, size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
964
965/**
966 * Same as RTMemEfDupExTag except that it's fenced.
967 *
968 * @returns New heap block with the duplicate data.
969 * @returns NULL if we're out of memory.
970 * @param pvSrc The memory to duplicate.
971 * @param cbSrc The amount of memory to duplicate.
972 * @param cbExtra The amount of extra memory to allocate and zero.
973 * @param pszTag Allocation tag used for statistics and such.
974 * @param SRC_POS The source position where call is being made from. Use
975 * RT_SRC_POS when possible. Optional.
976 */
977RTDECL(void *) RTMemEfDupEx(const void *pvSrc, size_t cbSrc, size_t cbExtra, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW_PROTO;
978
979/** @def RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF
980 * Define RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF to enable electric fence new and
981 * delete operators for classes which uses the RTMEMEF_NEW_AND_DELETE_OPERATORS
982 * macro.
983 */
984/** @def RTMEMEF_NEW_AND_DELETE_OPERATORS
985 * Defines the electric fence new and delete operators for a class when
986 * RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF is define.
987 */
988/** @def RTR0MEMEF_NEW_AND_DELETE_OPERATORS_IOKIT
989 * Defines the electric fence new and delete operators for an IOKit class when
990 * RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF is define.
991 *
992 * This differs from RTMEMEF_NEW_AND_DELETE_OPERATORS in that the memory we
993 * allocate is initialized to zero. It is also assuming we don't have nothrow
994 * variants and exceptions, so fewer variations.
995 */
996#if defined(RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF) && !defined(RTMEM_NO_WRAP_SOME_NEW_AND_DELETE_TO_EF)
997# if defined(RT_EXCEPTIONS_ENABLED)
998# define RTMEMEF_NEW_AND_DELETE_OPERATORS() \
999 void *operator new(size_t cb) RT_THROW(std::bad_alloc) \
1000 { \
1001 void *pv = RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
1002 if (RT_LIKELY(pv)) \
1003 return pv; \
1004 throw std::bad_alloc(); \
1005 } \
1006 void *operator new(size_t cb, const std::nothrow_t &nothrow_constant) RT_NO_THROW_DEF \
1007 { \
1008 NOREF(nothrow_constant); \
1009 return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
1010 } \
1011 void *operator new(size_t cb, void *pvBuf) RT_NO_THROW_DEF \
1012 { \
1013 NOREF(cb); \
1014 return pvBuf; \
1015 } \
1016 void *operator new[](size_t cb) RT_THROW(std::bad_alloc) \
1017 { \
1018 void *pv = RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
1019 if (RT_LIKELY(pv)) \
1020 return pv; \
1021 throw std::bad_alloc(); \
1022 } \
1023 void *operator new[](size_t cb, const std::nothrow_t &nothrow_constant) RT_NO_THROW_DEF \
1024 { \
1025 NOREF(nothrow_constant); \
1026 return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
1027 } \
1028 \
1029 void operator delete(void *pv) RT_NO_THROW_DEF \
1030 { \
1031 RTMemEfFree(pv, RT_SRC_POS); \
1032 } \
1033 void operator delete(void *pv, const std::nothrow_t &nothrow_constant) RT_NO_THROW_DEF \
1034 { \
1035 NOREF(nothrow_constant); \
1036 RTMemEfFree(pv, RT_SRC_POS); \
1037 } \
1038 void operator delete[](void *pv) RT_NO_THROW_DEF \
1039 { \
1040 RTMemEfFree(pv, RT_SRC_POS); \
1041 } \
1042 void operator delete[](void *pv, const std::nothrow_t &nothrow_constant) RT_NO_THROW_DEF \
1043 { \
1044 NOREF(nothrow_constant); \
1045 RTMemEfFree(pv, RT_SRC_POS); \
1046 } \
1047 \
1048 typedef int UsingElectricNewAndDeleteOperators
1049# else
1050# define RTMEMEF_NEW_AND_DELETE_OPERATORS() \
1051 void *operator new(size_t cb) \
1052 { \
1053 return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
1054 } \
1055 void *operator new(size_t cb, const std::nothrow_t &nothrow_constant) \
1056 { \
1057 NOREF(nothrow_constant); \
1058 return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
1059 } \
1060 void *operator new(size_t cb, void *pvBuf) RT_NO_THROW_DEF \
1061 { \
1062 NOREF(cb); \
1063 return pvBuf; \
1064 } \
1065 void *operator new[](size_t cb) \
1066 { \
1067 return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
1068 } \
1069 void *operator new[](size_t cb, const std::nothrow_t &nothrow_constant) \
1070 { \
1071 NOREF(nothrow_constant); \
1072 return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
1073 } \
1074 \
1075 void operator delete(void *pv) \
1076 { \
1077 RTMemEfFree(pv, RT_SRC_POS); \
1078 } \
1079 void operator delete(void *pv, const std::nothrow_t &nothrow_constant) \
1080 { \
1081 NOREF(nothrow_constant); \
1082 RTMemEfFree(pv, RT_SRC_POS); \
1083 } \
1084 void operator delete[](void *pv) \
1085 { \
1086 RTMemEfFree(pv, RT_SRC_POS); \
1087 } \
1088 void operator delete[](void *pv, const std::nothrow_t &nothrow_constant) \
1089 { \
1090 NOREF(nothrow_constant); \
1091 RTMemEfFree(pv, RT_SRC_POS); \
1092 } \
1093 \
1094 typedef int UsingElectricNewAndDeleteOperators
1095# endif
1096# define RTR0MEMEF_NEW_AND_DELETE_OPERATORS_IOKIT() \
1097 void *operator new(size_t cb) \
1098 { \
1099 return RTMemEfAllocZ(cb, RTMEM_TAG, RT_SRC_POS); \
1100 } \
1101 void *operator new[](size_t cb) \
1102 { \
1103 return RTMemEfAllocZ(cb, RTMEM_TAG, RT_SRC_POS); \
1104 } \
1105 \
1106 void operator delete(void *pv) \
1107 { \
1108 RTMemEfFree(pv, RT_SRC_POS); \
1109 } \
1110 void operator delete[](void *pv) \
1111 { \
1112 RTMemEfFree(pv, RT_SRC_POS); \
1113 } \
1114 \
1115 typedef int UsingElectricNewAndDeleteOperators
1116#else
1117# define RTMEMEF_NEW_AND_DELETE_OPERATORS() \
1118 typedef int UsingDefaultNewAndDeleteOperators
1119# define RTR0MEMEF_NEW_AND_DELETE_OPERATORS_IOKIT() \
1120 typedef int UsingDefaultNewAndDeleteOperators
1121#endif
1122#ifdef DOXYGEN_RUNNING
1123# define RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF
1124#endif
1125
1126/** @def RTMEM_WRAP_TO_EF_APIS
1127 * Define RTMEM_WRAP_TO_EF_APIS to wrap RTMem APIs to RTMemEf APIs.
1128 */
1129#if defined(RTMEM_WRAP_TO_EF_APIS) && !defined(RTMEM_NO_WRAP_TO_EF_APIS) \
1130 && ( defined(IN_RING3) || ( defined(IN_RING0) && !defined(IN_RING0_AGNOSTIC) && (defined(RT_OS_DARWIN) || 0) ) )
1131# define RTMemTmpAllocTag(cb, pszTag) RTMemEfTmpAlloc((cb), (pszTag), RT_SRC_POS)
1132# define RTMemTmpAllocZTag(cb, pszTag) RTMemEfTmpAllocZ((cb), (pszTag), RT_SRC_POS)
1133# define RTMemTmpFree(pv) RTMemEfTmpFree((pv), RT_SRC_POS)
1134# define RTMemTmpFreeZ(pv, cb) RTMemEfTmpFreeZ((pv), (cb), RT_SRC_POS)
1135# define RTMemAllocTag(cb, pszTag) RTMemEfAlloc((cb), (pszTag), RT_SRC_POS)
1136# define RTMemAllocZTag(cb, pszTag) RTMemEfAllocZ((cb), (pszTag), RT_SRC_POS)
1137# define RTMemAllocVarTag(cbUnaligned, pszTag) RTMemEfAllocVar((cbUnaligned), (pszTag), RT_SRC_POS)
1138# define RTMemAllocZVarTag(cbUnaligned, pszTag) RTMemEfAllocZVar((cbUnaligned), (pszTag), RT_SRC_POS)
1139# define RTMemReallocTag(pvOld, cbNew, pszTag) RTMemEfRealloc((pvOld), (cbNew), (pszTag), RT_SRC_POS)
1140# define RTMemReallocZTag(pvOld, cbOld, cbNew, pszTag) RTMemEfReallocZ((pvOld), (cbOld), (cbNew), (pszTag), RT_SRC_POS)
1141# define RTMemFree(pv) RTMemEfFree((pv), RT_SRC_POS)
1142# define RTMemFreeZ(pv, cb) RTMemEfFreeZ((pv), (cb), RT_SRC_POS)
1143# define RTMemDupTag(pvSrc, cb, pszTag) RTMemEfDup((pvSrc), (cb), (pszTag), RT_SRC_POS)
1144# define RTMemDupExTag(pvSrc, cbSrc, cbExtra, pszTag) RTMemEfDupEx((pvSrc), (cbSrc), (cbExtra), (pszTag), RT_SRC_POS)
1145#endif
1146#ifdef DOXYGEN_RUNNING
1147# define RTMEM_WRAP_TO_EF_APIS
1148#endif
1149
1150/**
1151 * Fenced drop-in replacement for RTMemTmpAllocTag.
1152 * @copydoc RTMemTmpAllocTag
1153 */
1154RTDECL(void *) RTMemEfTmpAllocNP(size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
1155
1156/**
1157 * Fenced drop-in replacement for RTMemTmpAllocZTag.
1158 * @copydoc RTMemTmpAllocZTag
1159 */
1160RTDECL(void *) RTMemEfTmpAllocZNP(size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
1161
1162/**
1163 * Fenced drop-in replacement for RTMemTmpFree.
1164 * @copydoc RTMemTmpFree
1165 */
1166RTDECL(void) RTMemEfTmpFreeNP(void *pv) RT_NO_THROW_PROTO;
1167
1168/**
1169 * Fenced drop-in replacement for RTMemTmpFreeZ.
1170 * @copydoc RTMemTmpFreeZ
1171 */
1172RTDECL(void) RTMemEfTmpFreeZNP(void *pv, size_t cb) RT_NO_THROW_PROTO;
1173
1174/**
1175 * Fenced drop-in replacement for RTMemAllocTag.
1176 * @copydoc RTMemAllocTag
1177 */
1178RTDECL(void *) RTMemEfAllocNP(size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
1179
1180/**
1181 * Fenced drop-in replacement for RTMemAllocZTag.
1182 * @copydoc RTMemAllocZTag
1183 */
1184RTDECL(void *) RTMemEfAllocZNP(size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
1185
1186/**
1187 * Fenced drop-in replacement for RTMemAllocVarTag
1188 * @copydoc RTMemAllocVarTag
1189 */
1190RTDECL(void *) RTMemEfAllocVarNP(size_t cbUnaligned, const char *pszTag) RT_NO_THROW_PROTO;
1191
1192/**
1193 * Fenced drop-in replacement for RTMemAllocZVarTag.
1194 * @copydoc RTMemAllocZVarTag
1195 */
1196RTDECL(void *) RTMemEfAllocZVarNP(size_t cbUnaligned, const char *pszTag) RT_NO_THROW_PROTO;
1197
1198/**
1199 * Fenced drop-in replacement for RTMemReallocTag.
1200 * @copydoc RTMemReallocTag
1201 */
1202RTDECL(void *) RTMemEfReallocNP(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW_PROTO;
1203
1204/**
1205 * Fenced drop-in replacement for RTMemReallocZTag.
1206 * @copydoc RTMemReallocZTag
1207 */
1208RTDECL(void *) RTMemEfReallocZNP(void *pvOld, size_t cbOld, size_t cbNew, const char *pszTag) RT_NO_THROW_PROTO;
1209
1210/**
1211 * Fenced drop-in replacement for RTMemFree.
1212 * @copydoc RTMemFree
1213 */
1214RTDECL(void) RTMemEfFreeNP(void *pv) RT_NO_THROW_PROTO;
1215
1216/**
1217 * Fenced drop-in replacement for RTMemFreeZ.
1218 * @copydoc RTMemFreeZ
1219 */
1220RTDECL(void) RTMemEfFreeZNP(void *pv, size_t cb) RT_NO_THROW_PROTO;
1221
1222/**
1223 * Fenced drop-in replacement for RTMemDupExTag.
1224 * @copydoc RTMemDupTag
1225 */
1226RTDECL(void *) RTMemEfDupNP(const void *pvSrc, size_t cb, const char *pszTag) RT_NO_THROW_PROTO;
1227
1228/**
1229 * Fenced drop-in replacement for RTMemDupExTag.
1230 * @copydoc RTMemDupExTag
1231 */
1232RTDECL(void *) RTMemEfDupExNP(const void *pvSrc, size_t cbSrc, size_t cbExtra, const char *pszTag) RT_NO_THROW_PROTO;
1233
1234/** @} */
1235
1236RT_C_DECLS_END
1237
1238/** @} */
1239
1240
1241#endif /* !IPRT_INCLUDED_mem_h */
1242
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